package com.ruoyi.hualian.service.impl;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.hualian.domain.*;
import com.ruoyi.hualian.service.*;
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.hualian.mapper.HlTimingPulleyMapper;

import javax.servlet.http.HttpServletResponse;

/**
 * 同步轮Service业务层处理
 *
 * @author hujian
 */
@Service
public class HlTimingPulleyServiceImpl implements IHlTimingPulleyService
{
    private static final Logger log = LoggerFactory.getLogger(HttpUtils.class);

    @Autowired
    private HlTimingPulleyMapper hlTimingPulleyMapper;

    @Autowired
    private IHlToothService hlToothService;

    @Autowired
    private IHlMaterialService hlMaterialService;

    @Autowired
    private IHlMaterialOdService hlMaterialOdService;

    @Autowired
    private IHlBandwidthService hlBandwidthService;

    @Autowired
    private IHlFlangeService hlFlangeService;

    @Autowired
    private IHlScrewService hlScrewService;

    @Autowired
    private ExcelService excelService;

    @Autowired
    private IHlBearingService hlBearingService;

    @Autowired
    private IHlOtherCommodityService hlOtherCommodityService;

    @Autowired
    private IHlOtherCommodityDetailsService hlOtherCommodityDetailsService;

    @Autowired
    private IHlKeywayService hlKeywayService;

    /**
     * 根据集合插入数据库
     * @param hlTimingPulleyList 集合
     * @return 结果
     */
    @Override
    public int insertList(List<HlTimingPulley> hlTimingPulleyList) {
        // 五百条数据插入一次
        List<HlTimingPulley> timingPulleyList = new ArrayList<>();

        int i = 0;
        for (; i < hlTimingPulleyList.size(); i++) {
            timingPulleyList.add(hlTimingPulleyList.get(i));
            if (i % 500 == 0) {
                int ii = hlTimingPulleyMapper.insertList(timingPulleyList);
                timingPulleyList = new ArrayList<>();
            }
        }
        hlTimingPulleyMapper.insertList(timingPulleyList);
        return i;
    }

    /**
     * 根据已知信息查询具体对象信息
     * @param hlTimingPulley 已知信息
     * @return 具体对象信息
     */
    @Override
    public HlTimingPulley selectOne(HlTimingPulley hlTimingPulley) {
        LambdaQueryWrapper<HlTimingPulley> hlTimingPulleyWrapper = new LambdaQueryWrapper<>();

        hlTimingPulleyWrapper.eq(HlTimingPulley::getTpType, hlTimingPulley.getTpType())
                .eq(HlTimingPulley::getTpMaterial, hlTimingPulley.getTpMaterial())
                .eq(HlTimingPulley::getTpToothBandwidth, hlTimingPulley.getTpToothBandwidth())
                .eq(HlTimingPulley::getTpTeethNum, hlTimingPulley.getTpTeethNum())
                .eq(HlTimingPulley::getTpShape, hlTimingPulley.getTpShape());

        return hlTimingPulleyMapper.selectOne(hlTimingPulleyWrapper);
    }

    /**
     * 非标查询
     * 根据已知信息查询具体对象信息
     * @param hlTimingPulley 已知信息
     * @return 具体对象信息
     */
    public HlTimingPulley selectNonstandard(HlTimingPulley hlTimingPulley) {
        LambdaQueryWrapper<HlTimingPulley> hlTimingPulleyWrapper = new LambdaQueryWrapper<>();

        hlTimingPulleyWrapper.eq(HlTimingPulley::getTpType, hlTimingPulley.getTpType())
                .eq(HlTimingPulley::getTpMaterial, hlTimingPulley.getTpMaterial())
                .likeRight(HlTimingPulley::getTpToothBandwidth, hlTimingPulley.getTpToothBandwidth())
                .eq(HlTimingPulley::getTpTeethNum, hlTimingPulley.getTpTeethNum())
                .eq(HlTimingPulley::getTpShape, hlTimingPulley.getTpShape())
                .last("limit 1");

        return hlTimingPulleyMapper.selectOne(hlTimingPulleyWrapper);
    }

    /**
     * 查询同步轮类型集合
     */
    @Override
    public List<String> selectTpTypeList() {
        return hlTimingPulleyMapper.selectDistinctTpTypeList();
    }

    /**
     * 根据前端参数查询同步轮齿数集合
     * @param parameter TP-A(铝)-MXL-025
     */
    @Override
    public List<String> selectTpBandwidthListForParameter(String parameter) {
        String[] split = parameter.split("-");
        String tpType = split[0];
        if (tpType.contains("TP")) {
            tpType = "TP";
        } else if (tpType.contains("IG")) {
            tpType = "IG";
        }
        String tpToothBandwidth = split[2] + split[3];

        HashMap<String, String> map = new HashMap<>();
        map.put("tpType", tpType);
        map.put("tpToothBandwidth", tpToothBandwidth);

        return hlTimingPulleyMapper.selectTpBandwidthListForParameter(map);
    }


    /**
     * 同步轮Excel模板导入数据库
     *
     * @param hlTimingPulleys Excel模板生成集合
     * @param containBK 材质是否含有B·K
     * @param insertDatabase 数据是否插入数据库
     * @return 结果
     */
    @Override
    public AjaxResult excelTimingPulley(List<HlTimingPulley> hlTimingPulleys, Boolean containBK, Boolean insertDatabase) {
        HlTimingPulley hlTimingPulley = hlTimingPulleys.get(0);
        String tpMaterial = hlTimingPulley.getTpMaterial();
        String tpToothBandwidth = hlTimingPulley.getTpToothBandwidth();
        String tpShape = hlTimingPulley.getTpShape();

        String[] splitMaterial = tpMaterial.split("-");
        String[] splitToothBandwidth = tpToothBandwidth.split("-");
        String[] splitShape = tpShape.split("-");


        List<HlTimingPulley> hlTimingPulleyList = new ArrayList<>();
        for (int i = 0; i < splitMaterial.length; i++) {
            for (int ii = 0; ii < splitToothBandwidth.length; ii++) {
                for (int iii = 0; iii < splitShape.length; iii++) {
                    for (int iiii = 0; iiii < hlTimingPulleys.size(); iiii++) {
                        {
                            String shape = splitShape[iii];
                            if ("B".equals(splitShape[iii])) {
                                if (containBK) {
                                    if (ObjectUtils.isNotEmpty(hlTimingPulleys.get(iiii).getTpE()) && ObjectUtils.isNotEmpty(hlTimingPulleys.get(iiii).getTpD())
                                            && new BigDecimal(hlTimingPulleys.get(iiii).getTpE()).compareTo(new BigDecimal(hlTimingPulleys.get(iiii).getTpD())) > 0) {
                                        shape = "B";
                                    } else {
                                        shape = "K";
                                    }
                                }
                                if (ObjectUtils.isNotEmpty(hlTimingPulleys.get(iiii).getTpDe())) {
                                    shape = "D";
                                }
                            }
                            HlTimingPulley timingPulley = new HlTimingPulley();
                            timingPulley.setTpType(hlTimingPulley.getTpType());
                            timingPulley.setTpMaterial(splitMaterial[i]);
                            timingPulley.setTpToothBandwidth(splitToothBandwidth[ii]);
                            timingPulley.setTpTeethNum(hlTimingPulleys.get(iiii).getTpTeethNum());
                            timingPulley.setTpShape(shape);
                            timingPulley.setTpAxleHoleType(hlTimingPulley.getTpAxleHoleType());
                            timingPulley.setTpPd(hlTimingPulleys.get(iiii).getTpPd());
                            timingPulley.setTpOd(hlTimingPulleys.get(iiii).getTpOd());
                            timingPulley.setTpMinD(hlTimingPulleys.get(iiii).getTpMinD());
                            timingPulley.setTpMaxD(hlTimingPulleys.get(iiii).getTpMaxD());
                            timingPulley.setTpD(hlTimingPulleys.get(iiii).getTpD());
                            timingPulley.setTpF(hlTimingPulleys.get(iiii).getTpF());
                            timingPulley.setTpE(hlTimingPulleys.get(iiii).getTpE());
                            timingPulley.setTpT(hlTimingPulleys.get(iiii).getTpT());
                            timingPulley.setTpDe(hlTimingPulleys.get(iiii).getTpDe());
                            timingPulley.setTpAhd(hlTimingPulleys.get(iiii).getTpAhd());
                            timingPulley.setTpApd(hlTimingPulleys.get(iiii).getTpApd());
                            timingPulley.setTpApm(hlTimingPulleys.get(iiii).getTpApm());
                            timingPulley.setTpAnd(hlTimingPulleys.get(iiii).getTpAnd());
                            timingPulley.setTpAnm(hlTimingPulleys.get(iiii).getTpAnm());
                            timingPulley.setTpAnb(hlTimingPulleys.get(iiii).getTpAnb());
                            timingPulley.setTpAnt(hlTimingPulleys.get(iiii).getTpAnt());
                            timingPulley.setTpAcd(hlTimingPulleys.get(iiii).getTpAcd());
                            timingPulley.setTpAcm(hlTimingPulleys.get(iiii).getTpAcm());
                            timingPulley.setTpAcb(hlTimingPulleys.get(iiii).getTpAcb());
                            timingPulley.setTpAct(hlTimingPulleys.get(iiii).getTpAct());
                            timingPulley.setTpAvd(hlTimingPulleys.get(iiii).getTpAvd());
                            timingPulley.setTpAvz(hlTimingPulleys.get(iiii).getTpAvz());
                            timingPulley.setTpAvj(hlTimingPulleys.get(iiii).getTpAvj());
                            timingPulley.setTpAyd(hlTimingPulleys.get(iiii).getTpAyd());
                            timingPulley.setTpAyq(hlTimingPulleys.get(iiii).getTpAyq());
                            timingPulley.setTpAyr(hlTimingPulleys.get(iiii).getTpAyr());
                            timingPulley.setTpAys(hlTimingPulleys.get(iiii).getTpAys());
                            timingPulley.setTpAyt(hlTimingPulleys.get(iiii).getTpAyt());
                            timingPulley.setTpAwbd(hlTimingPulleys.get(iiii).getTpAwbd());
                            timingPulley.setTpAwbq(hlTimingPulleys.get(iiii).getTpAwbq());
                            timingPulley.setTpAwbr(hlTimingPulleys.get(iiii).getTpAwbr());
                            timingPulley.setTpAwbs(hlTimingPulleys.get(iiii).getTpAwbs());
                            timingPulley.setTpAwbt(hlTimingPulleys.get(iiii).getTpAwbt());
                            timingPulley.setTpBhd(hlTimingPulleys.get(iiii).getTpBhd());
                            timingPulley.setTpBpd(hlTimingPulleys.get(iiii).getTpBpd());
                            timingPulley.setTpBpm(hlTimingPulleys.get(iiii).getTpBpm());
                            timingPulley.setTpBnd(hlTimingPulleys.get(iiii).getTpBnd());
                            timingPulley.setTpBnm(hlTimingPulleys.get(iiii).getTpBnm());
                            timingPulley.setTpBnb(hlTimingPulleys.get(iiii).getTpBnb());
                            timingPulley.setTpBnt(hlTimingPulleys.get(iiii).getTpBnt());
                            timingPulley.setTpBcd(hlTimingPulleys.get(iiii).getTpBcd());
                            timingPulley.setTpBcm(hlTimingPulleys.get(iiii).getTpBcm());
                            timingPulley.setTpBcb(hlTimingPulleys.get(iiii).getTpBcb());
                            timingPulley.setTpBct(hlTimingPulleys.get(iiii).getTpBct());
                            timingPulley.setTpBvd(hlTimingPulleys.get(iiii).getTpBvd());
                            timingPulley.setTpBvz(hlTimingPulleys.get(iiii).getTpBvz());
                            timingPulley.setTpBvj(hlTimingPulleys.get(iiii).getTpBvj());
                            timingPulley.setTpBfd(hlTimingPulleys.get(iiii).getTpBfd());
                            timingPulley.setTpBfz(hlTimingPulleys.get(iiii).getTpBfz());
                            timingPulley.setTpBfj(hlTimingPulleys.get(iiii).getTpBfj());
                            timingPulley.setTpKhd(hlTimingPulleys.get(iiii).getTpKhd());
                            timingPulley.setTpKpd(hlTimingPulleys.get(iiii).getTpKpd());
                            timingPulley.setTpKpm(hlTimingPulleys.get(iiii).getTpKpm());
                            timingPulley.setTpDhd(hlTimingPulleys.get(iiii).getTpDhd());
                            timingPulley.setTpDpd(hlTimingPulleys.get(iiii).getTpDpd());
                            timingPulley.setTpDpm(hlTimingPulleys.get(iiii).getTpDpm());
                            timingPulley.setTpDndd(hlTimingPulleys.get(iiii).getTpDndd());
                            timingPulley.setTpDnm(hlTimingPulleys.get(iiii).getTpDnm());
                            timingPulley.setTpDnd(hlTimingPulleys.get(iiii).getTpDnd());
                            timingPulley.setTpDnt(hlTimingPulleys.get(iiii).getTpDnt());
                            timingPulley.setTpDcdd(hlTimingPulleys.get(iiii).getTpDcdd());
                            timingPulley.setTpDcm(hlTimingPulleys.get(iiii).getTpDcm());
                            timingPulley.setTpDcd(hlTimingPulleys.get(iiii).getTpDcd());
                            timingPulley.setTpDct(hlTimingPulleys.get(iiii).getTpDct());

                            timingPulley.setTpShareA(hlTimingPulleys.get(iiii).getTpShareA().split("-")[ii]);
                            timingPulley.setTpShareB(hlTimingPulleys.get(iiii).getTpShareB().split("-")[ii]);
                            timingPulley.setTpAluminiumA(hlTimingPulleys.get(iiii).getTpAluminiumA().split("-")[ii]);
                            timingPulley.setTpAluminiumB(hlTimingPulleys.get(iiii).getTpAluminiumB().split("-")[ii]);
                            timingPulley.setTpIronA(hlTimingPulleys.get(iiii).getTpIronA().split("-")[ii]);
                            timingPulley.setTpIronB(hlTimingPulleys.get(iiii).getTpIronB().split("-")[ii]);

                            hlTimingPulleyList.add(timingPulley);
                        }
                    }
                }
            }
        }
        if (insertDatabase) {
            int i = hlTimingPulleyMapper.insertList(hlTimingPulleyList);
        }
        log.info("插入数据库的数据大小 ==> {}", hlTimingPulleyList.size());
        return null;
    }


    /**
     * 华链同步轮及相关产品成本和利润计算
     *
     * @param commodityCode   商品编码
     * @param bandwidthW 带宽W
     * @param bandwidthL 带宽L
     * @param consolePrinting 是否输出控制台打印日志
     * @return 结果
     */
    @Override
    public AjaxResult costPrice(String commodityCode, BigDecimal bandwidthW, BigDecimal bandwidthL, Boolean consolePrinting, String authority) {
        /*
            TPH-XL050-26-A-Y-d18-Q22-R22-S6-T6

         */
        /*
            IGH-H150-16-W-6002
            IGH-H150-16-W-6002
            IGD-S8M400-28-W-6202
         */

        log.info("前端传入查询商品编码 ==> {}", commodityCode);
        if (ObjectUtils.isEmpty(commodityCode)) {
            return AjaxResult.error("请输入型号进行查价");
        }
        // 去除空格
        commodityCode = commodityCode.replace(" ", "");
        String start = commodityCode.substring(0, 2);

        // 非标
        if ("Z-".equals(start)) {
            log.info("非标带宽W ==> {}", bandwidthW);
            log.info("非标带宽L ==> {}", bandwidthL);

            if ("TP".equals(commodityCode.substring(2, 4))) {
                return tpCostPrice(commodityCode, bandwidthW, bandwidthL, consolePrinting, true, authority);
            }
        } else {
            if ("TP".equals(start)) {
                return tpCostPrice(commodityCode, bandwidthW, bandwidthL, consolePrinting, false, authority);
            } else if ("IG".equals(start)) {
                return igCostPrice(commodityCode, bandwidthW, bandwidthL, consolePrinting, false, authority);
            }
        }
        return AjaxResult.error("数据库中暂无此编码信息，请联系管理员");
    }

    /**
     * TP 同步轮成本和利润计算
     * @param commodityCode 商品编码
     * @param consolePrinting 是否输出控制台打印日志
     * @param nonstandard 是否为非标
     * @return 结果
     */
    public AjaxResult tpCostPrice(String commodityCode, BigDecimal bandwidthW, BigDecimal bandwidthL, Boolean consolePrinting, Boolean nonstandard, String authority) {
        if (nonstandard) {
            commodityCode = commodityCode.substring(2);
        }

        String[] split = commodityCode.split("-");

        if (split.length <= 5 || commodityCode.matches(".*[\\u4e00-\\u9fa5].*") || !("d".equals(split[5].substring(0, 1)) || "D".equals(split[5].substring(0, 1)))) {
            return AjaxResult.error("型号输入不正确");
        }
        log.info("commodityCode ==> {}", commodityCode);
        // 输入商品编码的 d 内孔直径
        // 删除字符串中所有的 'K' 字符
        if (split[5].contains("K")) {
            split[5] = split[5].replace("K", "");
        } else if (split[5].contains("k")) {
            split[5] = split[5].replace("k", "");
        }
        BigDecimal d = new BigDecimal(split[5].substring(1));

        // 查询 材质表 hl_material
        HlMaterial material = new HlMaterial();
        // 特殊材质
        if ("HK".equals(split[0].substring(split[0].length() - 2))) {
            material.setMaterialMark("HK");
        } else {
            material.setMaterialMark(split[0].substring(split[0].length() - 1));
        }
        HlMaterial hlMaterial = hlMaterialService.selectOne(material);
        if (ObjectUtils.isEmpty(hlMaterial)) {
            return AjaxResult.error("数据库中暂无：" + material.getMaterialMark() + "此材质");
        }

        // 查询 材质OD表 hl_material_od 的到现实具体有此直径的铝棒
        // 成品所需要的材料表 hl_material_Od
        String materialType = hlMaterial.getMaterialType();
        HlMaterialOd materialOd = new HlMaterialOd();
        materialOd.setMaterialType(materialType);
        List<HlMaterialOd> materialOdList = hlMaterialOdService.selectList(materialOd);

        Pattern pattern = null;
        String A = null;
        if (nonstandard) {
            // 正则表达式: 使字符串A后面的字符被截取
            pattern = Pattern.compile("A(\\d+)");
            Matcher matcher = pattern.matcher(split[1]);
            if (!matcher.find()) {
                return AjaxResult.error("非标带宽数据错误，请检查后填写");
            }
            A = matcher.group(1);
        }

        // 齿形
        String tooth = null;
        if (nonstandard) {
            tooth = split[1].substring(0, split[1].length() - 1 - A.length());
        } else {
            tooth = split[1].substring(0, split[1].length() - 3);
        }

        // 查询 齿距 hl_tooth
        HlTooth t = new HlTooth();
        t.setTooth(tooth);
        HlTooth hlTooth = hlToothService.selectOne(t);
        if (ObjectUtils.isEmpty(hlTooth)) {
            return AjaxResult.error("齿形数据异常，请联系管理员");
        }

        // 同步轮代表的型号 TP
        String tp = split[0].substring(0, 2);
        // 同步轮形状
        String tpShape = split[3];
        // 带宽 永远是后三位
        String bandwidth = null;
        // 齿数
        BigDecimal teethNum = new BigDecimal(split[2]);

        // 齿形带宽
        String toothBandwidth = null;
        List<HlBandwidth> hlBandwidths = null;
        HlBandwidth hlBandwidth = null;
        // 不是非标
        if (!nonstandard) {
            toothBandwidth = split[1];
            bandwidth = split[1].substring(split[1].length() - 3);

            // 查询 带宽表 hl_bandwidth
            // 以此获得 bandwidth_a 、 bandwidth_w 、 bandwidth_l 信息
            HlBandwidth bd = new HlBandwidth();
            bd.setBandwidth(toothBandwidth);
            hlBandwidths = hlBandwidthService.selectHlBandwidthList(bd);

            hlBandwidth = resultHlBandwidth(teethNum, hlBandwidths);
            if (ObjectUtils.isEmpty(hlBandwidth)) {
                return AjaxResult.error("齿形带宽数据异常，请联系管理员");
            }
        }
        // 非标
        else {
            hlBandwidth = new HlBandwidth();

            // 正则表达式: 字符串只能包含数字
            pattern = Pattern.compile("\\d+");
            if (!A.matches(pattern.pattern())) {
                return AjaxResult.error("非标带宽数据错误，请检查后填写");
            }

            BigDecimal bandwidthA = new BigDecimal(A);
            hlBandwidth.setBandwidthA(bandwidthA);

            if (ObjectUtils.isEmpty(bandwidthW)) {
                bandwidthW = hlTooth.getWa().add(bandwidthA);
                hlBandwidth.setBandwidthW(bandwidthW);
            } else {
                hlBandwidth.setBandwidthW(bandwidthW);
            }

            if (ObjectUtils.isEmpty(bandwidthL)) {
                if ("B".equals(tpShape) || "D".equals(tpShape) || "K".equals(tpShape)) {
                    return AjaxResult.error("同步轮形状为B·D·K时, 非标带宽L必填");
                }
                bandwidthL = new BigDecimal("0");
            }
            hlBandwidth.setBandwidthL(bandwidthL);
        }

        // 同步轮材质
        String materialMark = material.getMaterialMark();


        // 查询商品的详细信息 hl_timing_pulley 同步轮表
        HlTimingPulley timingPulley = new HlTimingPulley();
        HlTimingPulley hlTimingPulley = null;
        timingPulley.setTpType(tp);
        timingPulley.setTpMaterial(materialMark);
        timingPulley.setTpTeethNum(split[2]);
        timingPulley.setTpShape(tpShape);
        // 不是非标
        if (!nonstandard) {
            timingPulley.setTpToothBandwidth(toothBandwidth);
            hlTimingPulley = this.selectOne(timingPulley);
            if (ObjectUtils.isEmpty(hlTimingPulley)) {
                return AjaxResult.error("同步轮数据库暂无此型号，请联系管理员");
            }
        }
        // 非标
        else {
            timingPulley.setTpToothBandwidth(tooth);
            hlTimingPulley = this.selectNonstandard(timingPulley);
            if (ObjectUtils.isEmpty(hlTimingPulley)) {
                return AjaxResult.error("同步轮数据库暂无此型号，请联系管理员");
            }
        }
        // 同步轮轴孔类型
        String tpAxleHoleType = split[4];

        // 同步轮成品的信息:   O.D.    重量
        Map<String, BigDecimal> finishedProductInformationMap = resultFinishedProductInformationMap(teethNum, hlTooth, hlTimingPulley,
                hlBandwidth, tpShape, hlMaterial, consolePrinting);
        // 同步轮成品的信息:   O.D.
        BigDecimal OD = finishedProductInformationMap.get("O.D.");
        // 同步轮成品的信息:   重量
        BigDecimal finishedMass = finishedProductInformationMap.get("finishedMass");

        // 同步轮材料尺寸
        String materialSize = resultMaterialSize(OD, materialOdList, tpShape, hlBandwidth, nonstandard,consolePrinting);

        // 同步轮材料重量和材料费用
        Map<String, BigDecimal> materialMassAndMaterialCostMap = resultMaterialMassAndMaterialCostMap(materialSize, hlMaterial, consolePrinting);
        // 同步轮材料重量
        BigDecimal materialMass = materialMassAndMaterialCostMap.get("materialMass");
        // 同步轮材料费用
        BigDecimal materialPrice = materialMassAndMaterialCostMap.get("materialPrice");

        // 材料切断
        BigDecimal materialCutOff = resultMaterialCutOff(materialSize, materialPrice);

        // 车A时间
        BigDecimal vehicleATime = resultVehicleATime(materialSize, OD, hlBandwidth,
                hlTimingPulley, tpShape, materialMark);
        // 车B时间
        BigDecimal vehicleBTime = resultVehicleBTime(materialSize, OD, hlBandwidth,
                hlTimingPulley, tpShape, materialMark);
        // 车床费用
        BigDecimal latheCost = resultLatheCost(vehicleATime, vehicleBTime);

        // 滚齿时间
        BigDecimal hobbingTime = resultHobbingTime(hlMaterial, teethNum, hlBandwidth);
        // 滚齿费用
        BigDecimal hobbingCost = resultHobbingCost(tooth, teethNum, hobbingTime);

        // 攻牙时间
        BigDecimal attackTeethTime = resultAttackTeethTime(tpShape, hlTimingPulley);
        // 攻牙费用
        BigDecimal attackTeethCost = resultAttackTeethCost(attackTeethTime);

        // 拉键槽时间
        BigDecimal pullingKeyGrooveTime = resultPullingKeyGrooveTime(tpShape, hlBandwidth, tpAxleHoleType, d);
        // 拉键槽费用
        BigDecimal pullingKeyGrooveCost = resultPullingKeyGrooveCost(pullingKeyGrooveTime);

        // 压挡圈时间
        BigDecimal pressureRetainingRingTime = resultPressureRetainingRingTime();
        // 压挡圈费用
        BigDecimal pressureRetainingRingCost = resultPressureRetainingRingCost(pressureRetainingRingTime);

        // 表面处理费用
        BigDecimal surfaceTreatmentCost = resultSurfaceTreatmentCost(hlMaterial, finishedMass);

        // 挡圈费用
        BigDecimal flangeCost = resultFlangeCost(materialMark, tooth, hlTimingPulley, tpShape);

        // 螺丝费用
        BigDecimal screwCost = resultScrewCost(tooth, d);

        // 装配费用
        BigDecimal assembleCost = resultAssembleCost();

        // 包装费用
        BigDecimal packageCost = resultPackageCost(OD);

        // 物流费用
        BigDecimal logisticsCost = resultLogisticsCost(finishedMass);

        // 改孔时间
        BigDecimal holeModificationTime = resultHoleModificationTime(hlTimingPulley, d, materialMark,
                tpShape, hlBandwidth, OD);

        // 改孔费用
        BigDecimal holeModificationCost = resultHoleModificationCost(holeModificationTime, d, hlTimingPulley);

        // 额外成本
        BigDecimal additionalCost = resultAdditionalCost(hlTimingPulley, materialMark, new BigDecimal("0"), tpShape);

        // 成本
        HashMap<String, BigDecimal> resultCostMap = resultCostMap(tpAxleHoleType, materialPrice, materialCutOff,
                flangeCost, surfaceTreatmentCost, logisticsCost,
                latheCost, hobbingCost, pressureRetainingRingCost,
                packageCost, assembleCost, screwCost,
                attackTeethCost, pullingKeyGrooveCost, holeModificationCost, additionalCost);

        String materialsPartsCost = resultCostMap.get("materialsPartsCost").setScale(2, RoundingMode.HALF_UP).toString();
        String processCost = resultCostMap.get("processCost").setScale(2, RoundingMode.HALF_UP).toString();
        String assessCost = resultCostMap.get("assessCost").setScale(2, RoundingMode.HALF_UP).toString();
        String retailPrice = resultCostMap.get("retailPrice").setScale(2, RoundingMode.HALF_UP).toString();
        String taxRetailPrice = resultCostMap.get("taxRetailPrice").setScale(2, RoundingMode.HALF_UP).toString();

        String num1 = resultCostMap.get("num1").setScale(2, RoundingMode.HALF_UP).toString();
        String num2 = resultCostMap.get("num2").setScale(2, RoundingMode.HALF_UP).toString();
        String num3 = resultCostMap.get("num3").setScale(2, RoundingMode.HALF_UP).toString();
        String num4 = resultCostMap.get("num4").setScale(2, RoundingMode.HALF_UP).toString();
        String num5 = resultCostMap.get("num5").setScale(2, RoundingMode.HALF_UP).toString();
        String num10 = resultCostMap.get("num10").setScale(2, RoundingMode.HALF_UP).toString();
        String num20 = resultCostMap.get("num20").setScale(2, RoundingMode.HALF_UP).toString();
        String num50 = resultCostMap.get("num50").setScale(2, RoundingMode.HALF_UP).toString();
        String num100 = resultCostMap.get("num100").setScale(2, RoundingMode.HALF_UP).toString();
        String num500 = resultCostMap.get("num500").setScale(2, RoundingMode.HALF_UP).toString();
        String num1000 = resultCostMap.get("num1000").setScale(2, RoundingMode.HALF_UP).toString();
        String num3000 = resultCostMap.get("num3000").setScale(2, RoundingMode.HALF_UP).toString();

        String taxNum1 = resultCostMap.get("taxNum1").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum2 = resultCostMap.get("taxNum2").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum3 = resultCostMap.get("taxNum3").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum4 = resultCostMap.get("taxNum4").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum5 = resultCostMap.get("taxNum5").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum10 = resultCostMap.get("taxNum10").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum20 = resultCostMap.get("taxNum20").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum50 = resultCostMap.get("taxNum50").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum100 = resultCostMap.get("taxNum100").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum500 = resultCostMap.get("taxNum500").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum1000 = resultCostMap.get("taxNum1000").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum3000 = resultCostMap.get("taxNum3000").setScale(2, RoundingMode.HALF_UP).toString();

        ResultTimingPulleyPrice timingPulleyPrice = new ResultTimingPulleyPrice(
                OD.setScale(2, RoundingMode.HALF_UP).toString(),
                finishedMass.setScale(2, RoundingMode.HALF_UP).toString(),
                materialSize,
                materialMass.setScale(2, RoundingMode.HALF_UP).toString(),
                materialPrice.setScale(2, RoundingMode.HALF_UP).toString(),
                materialCutOff.setScale(2, RoundingMode.HALF_UP).toString(),
                vehicleATime.setScale(2, RoundingMode.HALF_UP).toString(),
                vehicleBTime.setScale(2, RoundingMode.HALF_UP).toString(),
                latheCost.setScale(2, RoundingMode.HALF_UP).toString(),
                hobbingTime.setScale(2, RoundingMode.HALF_UP).toString(),
                hobbingCost.setScale(2, RoundingMode.HALF_UP).toString(),
                attackTeethTime.setScale(2, RoundingMode.HALF_UP).toString(),
                attackTeethCost.setScale(2, RoundingMode.HALF_UP).toString(),
                pullingKeyGrooveTime.setScale(2, RoundingMode.HALF_UP).toString(),
                pullingKeyGrooveCost.setScale(2, RoundingMode.HALF_UP).toString(),
                pressureRetainingRingTime.setScale(2, RoundingMode.HALF_UP).toString(),
                pressureRetainingRingCost.setScale(2, RoundingMode.HALF_UP).toString(),
                surfaceTreatmentCost.setScale(2, RoundingMode.HALF_UP).toString(),
                flangeCost.setScale(2, RoundingMode.HALF_UP).toString(),
                screwCost.setScale(2, RoundingMode.HALF_UP).toString(),
                assembleCost.setScale(2, RoundingMode.HALF_UP).toString(),
                packageCost.setScale(2, RoundingMode.HALF_UP).toString(),
                logisticsCost.setScale(2, RoundingMode.HALF_UP).toString(),
                holeModificationTime.setScale(2, RoundingMode.HALF_UP).toString(),
                holeModificationCost.setScale(2, RoundingMode.HALF_UP).toString(),
                materialsPartsCost,
                processCost,
                assessCost,
                retailPrice,
                taxRetailPrice,
                additionalCost.toString(),
                num1,
                num2,
                num3,
                num4,
                num5,
                num10,
                num20,
                num50,
                num100,
                num500,
                num1000,
                num3000,
                taxNum1,
                taxNum2,
                taxNum3,
                taxNum4,
                taxNum5,
                taxNum10,
                taxNum20,
                taxNum50,
                taxNum100,
                taxNum500,
                taxNum1000,
                taxNum3000,
                materialMark,
                tpShape,
                hlTimingPulley
        );
        if (consolePrinting) {
            String resultString = "O.D.:" + OD + "," +
                            "重量:" + finishedMass + "," +
                            "同步轮材料尺寸:" + materialSize + "," +
                            "同步轮材料重量:" + materialMass + "," +
                            "同步轮材料费用:" + materialPrice + "," +
                            "材料切断:" + materialCutOff + "," +
                            "车A时间:" + vehicleATime + "," +
                            "车B时间:" + vehicleBTime + "," +
                            "车床费用:" + latheCost + "," +
                            "滚齿时间:" + hobbingTime + "," +
                            "滚齿费用:" + hobbingCost + "," +
                            "攻牙时间:" + attackTeethTime + "," +
                            "攻牙费用:" + attackTeethCost + "," +
                            "拉键槽时间:" + pullingKeyGrooveTime + "," +
                            "拉键槽费用:" + pullingKeyGrooveCost + "," +
                            "压挡圈时间:" + pressureRetainingRingTime + "," +
                            "压挡圈费用:" + pressureRetainingRingCost + "," +
                            "表面处理费用:" + surfaceTreatmentCost + "," +
                            "挡圈费用:" + flangeCost + "," +
                            "螺丝费用:" + screwCost + "," +
                            "螺丝费用:" + assembleCost + "," +
                            "包装费用:" + packageCost + "," +
                            "物流费用:" + logisticsCost + "," +
                            "改孔时间:" + holeModificationTime + "," +
                            "改孔费用:" + holeModificationCost + "," +
                            "料件成本:" + materialsPartsCost + "," +
                            "加工成本:" + processCost + "," +
                            "合计成本:" + assessCost + "," +
                            "零售价:" + retailPrice + "," +
                            "含税零售价:" + taxRetailPrice + "," +
                            "额外成本:" + additionalCost + "," +
                            "1件:" + num1 + "," +
                            "2件:" + num2 + "," +
                            "3件:" + num3 + "," +
                            "4件:" + num4 + "," +
                            "5件:" + num5 + "," +
                            "10+价:" + num10 + "," +
                            "20+价:" + num20 + "," +
                            "50+价:" + num50 + "," +
                            "100+价:" + num100 + "," +
                            "500+价:" + num500 + "," +
                            "1000+价:" + num1000 + "," +
                            "3000+价:" + num3000 + "," +
                            "含税1件:" + taxNum1 + "," +
                            "含税2件:" + taxNum2 + "," +
                            "含税3件:" + taxNum3 + "," +
                            "含税4件:" + taxNum4 + "," +
                            "含税5件:" + taxNum5 + "," +
                            "含税10+价:" + taxNum10 + "," +
                            "含税20+价:" + taxNum20 + "," +
                            "含税50+价:" + taxNum50 + "," +
                            "含税100+价:" + taxNum100 + "," +
                            "含税500+价:" + taxNum500 + "," +
                            "含税1000+价:" + taxNum1000 + "," +
                            "含税3000+价:" + taxNum3000;
            String[] pairs = resultString.split(",");

            LinkedHashMap<String, String> resultJsonMap = new LinkedHashMap<>();
            for (String pair : pairs) {
                String[] pairsSon = pair.split(":");
                resultJsonMap.put(pairsSon[0], pairsSon[1]);
            }
            log.info("价格详情 ==> {}", JSON.toJSONString(resultJsonMap));
        }
        // 如果形状是D则全部返回O
        if ("D".equals(tpShape)) {
            return AjaxResult.success(dTpShape());
        }
        if ("1".equals(authority)) {
            ResultTimingPulleyPrice timingPulleyPriceTwo = new ResultTimingPulleyPrice(
                    num1,
                    num2,
                    num3,
                    num4,
                    num5,
                    num10,
                    num20,
                    num50,
                    num100,
                    num500,
                    num1000,
                    num3000,
                    taxNum1,
                    taxNum2,
                    taxNum3,
                    taxNum4,
                    taxNum5,
                    taxNum10,
                    taxNum20,
                    taxNum50,
                    taxNum100,
                    taxNum500,
                    taxNum1000
            );
            return AjaxResult.success(timingPulleyPriceTwo);
        }
        return AjaxResult.success(timingPulleyPrice);
    }

    /**
     * 带宽表 hl_bandwidth 根据齿形带宽和齿数查出 HlBandwidth
     * bandwidth_a 、 bandwidth_w 、 bandwidth_l
     *
     * @param teethNum     齿数
     * @param hlBandwidths 数据集合
     * @return HlBandwidth
     */
    public HlBandwidth resultHlBandwidth(BigDecimal teethNum, List<HlBandwidth> hlBandwidths) {
        if (hlBandwidths.size() == 1) {
            return hlBandwidths.get(0);
        } else {
            for (int i = 0; i < hlBandwidths.size(); i++) {
                String bandwidthRange = hlBandwidths.get(i).getBandwidthRange();
                String[] split = bandwidthRange.split("-");

                if (split.length == 1) {
                    if (teethNum.compareTo(new BigDecimal(split[0])) >= 0) {
                        return hlBandwidths.get(i);
                    }
                } else {
                    BigDecimal min = new BigDecimal(split[0]);
                    BigDecimal max = new BigDecimal(split[1]);

                    if (teethNum.compareTo(min) >= 0 && teethNum.compareTo(max) < 0) {
                        return hlBandwidths.get(i);
                    }
                }
            }
        }
        return null;
    }

    /**
     * 成品的信息：   O.D.    重量
     *
     * @param teethNum 齿数
     * @param hlTooth 齿数表
     * @param hlTimingPulley 同步轮表
     * @param hlBandwidth 齿形带宽表
     * @param tpShape 同步轮形状
     * @param hlMaterial 材质表
     * @param consolePrinting 是否输出控制台打印日志
     * @return 结果
     */
    public Map<String, BigDecimal> resultFinishedProductInformationMap(BigDecimal teethNum, HlTooth hlTooth, HlTimingPulley hlTimingPulley,
                                                                    HlBandwidth hlBandwidth, String tpShape, HlMaterial hlMaterial,
                                                                    Boolean consolePrinting) {
        Map<String, BigDecimal> resultFinishedProductInformationMap = new HashMap<>();
        BigDecimal π = new BigDecimal(Math.PI);
        BigDecimal two = BigDecimal.valueOf(2);

        // C 周长 = 齿数 X 齿距
        BigDecimal C = teethNum.multiply(hlTooth.getPitch());
        // P.D.
        BigDecimal PD = C.divide(π, 3, RoundingMode.HALF_UP);
        // O.D.
        BigDecimal OD;
        // 若 r0 不为空, P.D. 减去 两倍 的 rO
        if (ObjectUtils.isNotEmpty(hlTooth.getR0())) {
            OD = PD.subtract(hlTooth.getR0()).subtract(hlTooth.getR0());
        } else {
            OD = PD;
        }

        // 如果查询同步轮类型齿数在数据库中有，就用数据库中的O.D.
        if (ObjectUtils.isNotEmpty(hlTimingPulley)) {
            OD = new BigDecimal(hlTimingPulley.getTpOd());
        }
        resultFinishedProductInformationMap.put("O.D.", OD);

        // tpMinD 对应Excel [ X -- mind ]
        BigDecimal tpMinD = new BigDecimal(hlTimingPulley.getTpMinD());
        // tpMinD 半径
        BigDecimal tpMinDr = tpMinD.divide(two, 3, RoundingMode.HALF_UP);
        // r 半径 对应Excel [ L -- O.D ]
        BigDecimal r = OD.divide(two, 3, RoundingMode.HALF_UP);
        // 同步轮 D
        BigDecimal D = new BigDecimal(hlTimingPulley.getTpD());
        BigDecimal Dr = D.divide(two, 3, RoundingMode.HALF_UP);

        BigDecimal multiplyR = r.multiply(r).multiply(π);
        BigDecimal multiplyTpMinDr = tpMinDr.multiply(tpMinDr).multiply(π);
        BigDecimal multiplyDr = Dr.multiply(Dr).multiply(π);
        BigDecimal bandwidthW = hlBandwidth.getBandwidthW();
        BigDecimal bandwidthL = hlBandwidth.getBandwidthL();

        // S = πr² 面积, 单位是 平方毫米 mm²
        BigDecimal S = new BigDecimal("0");
        // 同步轮的面积计算出来了，现在算体积
        BigDecimal V = new BigDecimal("0");
        if (ObjectUtils.equals("A", tpShape)) {
            // 公式: [ (OD/2)² * π - (d/2)² * π ] * W
            S = multiplyR.subtract(multiplyTpMinDr);
            // 同步轮的面积计算出来了，现在算体积 单位是 立方毫米 mm³
            V = S.multiply(bandwidthW);
            V = V.setScale(10, RoundingMode.HALF_UP); // 体积 mm³
        } else if (ObjectUtils.equals("B", tpShape) || ObjectUtils.equals("K", tpShape)) {
            // 带凸台的有两个圆柱体,体积是两个圆柱体相加,面积也是
            // 底下的圆柱体面积
            BigDecimal S1 = multiplyR.subtract(multiplyTpMinDr);
            // 凸台圆柱体面积
            BigDecimal S2 = multiplyDr.subtract(multiplyTpMinDr);
            // 公式: [ (OD/2)² * π - (d/2)² * π ] * W + [ (OD/2)² * π - (d/2)² * π ] * (L - W)
            // 同步轮的面积计算出来了，现在算体积 单位是 立方毫米 mm³
            BigDecimal S1V = S1.multiply(bandwidthW);
            BigDecimal S2V = S2.multiply(bandwidthL.subtract(bandwidthW));
            V = S1V.add(S2V);
        }

        // 材质的密度与单价
        // 密度 kg/m³
        BigDecimal density = hlMaterial.getMaterialDensity();

        // 将体积从立方毫米转换为立方米, 保留六位小数
        BigDecimal volumeInMeters = V.divide(new BigDecimal("1000000000"), 10, RoundingMode.HALF_UP);

        // 成品重量
        // 计算重量, 四舍五入并且保留三位小数
        BigDecimal finishedMass = density.multiply(volumeInMeters);
        resultFinishedProductInformationMap.put("finishedMass", finishedMass);

        if (consolePrinting) {
            log.info("同步轮成品的体积mm³ ==> {}", V);
            log.info("同步轮计算出来的O.D. ==> {}", OD);
            log.info("同步轮成品的重量 ==> {}", finishedMass);
        }
        return resultFinishedProductInformationMap;
    }

    /**
     * 同步轮材料尺寸
     *
     * @param OD 同步轮成品的信息:   O.D.
     * @param materialOdList 材质OD表
     * @param tpShape 同步轮形状
     * @param hlBandwidth 齿形带宽表
     * @param nonstandard 是否为非标
     * @param consolePrinting 是否输出控制台打印日志
     * @return 结果
     */
    public String resultMaterialSize(BigDecimal OD, List<HlMaterialOd> materialOdList, String tpShape,
                                     HlBandwidth hlBandwidth, Boolean nonstandard, Boolean consolePrinting) {
        // 同步轮材料尺寸
        StringBuilder materialSize = new StringBuilder();
        // 添加余量
        BigDecimal realityOD = OD.add(BigDecimal.valueOf(0.2)).add(BigDecimal.valueOf(0.8));
        // 之后还需在数据库中找个比之大的整数，现实铝棒是不可能生产有小数点位的直径
        realityOD = realityOD.setScale(0, RoundingMode.UP); // 向上取整
        for (HlMaterialOd materialOd : materialOdList) {
            BigDecimal od = BigDecimal.valueOf(materialOd.getOd());
            if (od.compareTo(realityOD) >= 0) {
                realityOD = od;
                break;
            }
        }

        BigDecimal WL = new BigDecimal("0");
        if (ObjectUtils.equals("A", tpShape)) {
            WL = hlBandwidth.getBandwidthW();
        } else if (ObjectUtils.equals("B", tpShape) || ObjectUtils.equals("K", tpShape)) {
            WL = hlBandwidth.getBandwidthL();
        }
        if (OD.compareTo(BigDecimal.valueOf(80)) > 0) {
            materialSize.append(realityOD).append("*").append(WL.add(BigDecimal.valueOf(3)).setScale(0, RoundingMode.UP));
        } else if (nonstandard) {
            materialSize.append(realityOD).append("*").append(WL.add(BigDecimal.valueOf(2)).setScale(0, RoundingMode.UP));
        } else {
            materialSize.append(realityOD).append("*").append(WL.add(BigDecimal.valueOf(2)).setScale(0, RoundingMode.UP));
        }
        if (consolePrinting) {
            log.info("同步轮现实材料的O.D. ==> {}", realityOD);
            log.info("同步轮材料尺寸 ==> {}", materialSize);
        }
        return materialSize.toString();
    }

    /**
     * 同步轮材料重量和同步轮材料费用
     *
     * @param materialSize 同步轮材料尺寸
     * @param hlMaterial 材质表
     * @return 结果
     */
    public Map<String, BigDecimal> resultMaterialMassAndMaterialCostMap(String materialSize, HlMaterial hlMaterial, Boolean consolePrinting) {
        Map<String, BigDecimal> resultMaterialMassAndMaterialCostMap = new HashMap<>();
        String[] materialSizeSplit = materialSize.split("\\*");
        // 材料外径
        BigDecimal D = new BigDecimal(materialSizeSplit[0]);
        // 材料内径
        BigDecimal d = new BigDecimal("0");
        // 材料长度
        BigDecimal materialLength = new BigDecimal(materialSizeSplit[1]);
        // π 圆周率
        BigDecimal π = new BigDecimal(Math.PI);
        BigDecimal two = BigDecimal.valueOf(2);

        // 材料外径 半径
        BigDecimal Dr = D.divide(two, 3, RoundingMode.HALF_UP);
        // 材料内径 半径
        BigDecimal dr = d.divide(two, 3, RoundingMode.HALF_UP);

        // 材料外径的圆柱体面积
        BigDecimal S1 = (Dr.multiply(Dr)).multiply(π);
        // 材料内径的圆柱体面积
        BigDecimal S2 = (dr.multiply(dr)).multiply(π);

        // 公式: [ (r/2)² * π - (rr/2)² * π ] * materialLength / 1000000000
        BigDecimal V = (S1.subtract(S2)).multiply(materialLength).divide(new BigDecimal("1000000000"), 10, RoundingMode.HALF_UP);
        // 材质的密度与单价 密度 kg/m³
        BigDecimal density = hlMaterial.getMaterialDensity();

        // 计算质量
        BigDecimal materialMass = density.multiply(V);

        // 计算材质费用
        BigDecimal materialPrice = new BigDecimal("0");

        // 同步轮材质
        String materialMark = hlMaterial.getMaterialMark();
        if (ObjectUtils.equals("A", materialMark) ||
                ObjectUtils.equals("H", materialMark) ||
                ObjectUtils.equals("HK", materialMark) ||
                ObjectUtils.equals("K", materialMark) ||
                ObjectUtils.equals("R", materialMark)) {
            materialPrice = materialMass.multiply(BigDecimal.valueOf(23));
        } else if (ObjectUtils.equals("F", materialMark) ||
                ObjectUtils.equals("C", materialMark) ||
                ObjectUtils.equals("D", materialMark)) {
            materialPrice = materialMass.multiply(BigDecimal.valueOf(6.5));
        } else if (ObjectUtils.equals("S", materialMark)) {
            materialPrice = materialMass.multiply(BigDecimal.valueOf(22));
        }

        resultMaterialMassAndMaterialCostMap.put("materialMass", materialMass);
        resultMaterialMassAndMaterialCostMap.put("materialPrice", materialPrice);
        if (consolePrinting) {
            log.info("同步轮材料重量 ==> {}", materialMass);
            log.info("同步轮材料费用 ==> {}", materialPrice);
        }
        return resultMaterialMassAndMaterialCostMap;
    }

    /**
     * 材料切断
     *
     * @param materialSize    材料尺寸
     * @param materialPrice 同步轮材料费用
     * @return 结果
     */
    public BigDecimal resultMaterialCutOff(String materialSize, BigDecimal materialPrice) {
        String[] materialSizeSplit = materialSize.split("\\*");
        if (new BigDecimal(materialSizeSplit[0]).compareTo(BigDecimal.valueOf(46)) > 0) {
            return materialPrice.divide(new BigDecimal(materialSizeSplit[1]), 3, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(4));
        } else {
            return materialPrice.divide(new BigDecimal(materialSizeSplit[1]), 3, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(2));
        }
    }

    /**
     * 车A时间
     *
     * @param materialSize 同步轮材料尺寸
     * @param OD 同步轮成品的信息:   O.D.
     * @param hlBandwidth 齿形带宽表
     * @param hlTimingPulley 同步轮表
     * @param tpShape 同步轮形状
     * @param materialMark 同步轮材质
     * @return 结果
     */
    public BigDecimal resultVehicleATime(String materialSize, BigDecimal OD, HlBandwidth hlBandwidth,
                                         HlTimingPulley hlTimingPulley, String tpShape, String materialMark) {

        // =IFS(
        //         $H3="A",
        //         IFS(
        //                 OR($D3="A",$D3="H",$D3="HK",$D3="K",$D3="R"),
        //                         N("多肉部分")+((((CD3)/2)^2*PI()-(CE3/2)^2*PI())*((CF3-$N3)/2)+(((CD3)/2)^2*PI()-(($L3+0.3)/2)^2*PI())*((CF3+$N3)/2)+((($L3+0.3)/2)^2*PI()-(($U3)/2)^2*PI())*(($N3-$M3)/2))/1500+9+
        //                         N("表面粗车")+(($L3+0.3)*PI()*((CF3+$M3)/2)+($U3)*PI()*(($N3-$M3)/2)+(($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI()+($X3-0.2)*PI()*((CF3+$N3)/2))/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*2.2,500*2.2)+12+
        //                         N("表面精车")+((($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI()+($U3)*PI()*(($N3-$M3)/2))/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*0.8,500*0.8)+6+
        //                         N("切断")+IF(CD3>46,0,(CD3)/2.零售1)+10+N("结束"),
        //                 OR($D3="F",$D3="C",$D3="D"),
        //                 N("多肉部分")+((((CD3)/2)^2*PI()-(CE3/2)^2*PI())*((CF3-$N3)/2)+(((CD3)/2)^2*PI()-(($L3+0.3)/2)^2*PI())*((CF3+$N3)/2)+((($L3+0.3)/2)^2*PI()-(($U3)/2)^2*PI())*(($N3-$M3)/2))/600+9+
        //                         N("表面粗车")+(($L3+0.3)*PI()*((CF3+$M3)/2)+($U3)*PI()*(($N3-$M3)/2)+(($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI()+($X3-0.2)*PI()*((CF3+$N3)/2))/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*1.2,500*1.2)+12+
        //                         N("表面精车")+((($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI()+($U3)*PI()*(($N3-$M3)/2))/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*0.5,500*0.5)+6+
        //                         N("切断")+IF(CD3>46,0,(CD3)/1.零售1)+10+N("结束")),
        //         OR($H3="B",$H3="K"),
        //         IFS(
        //                 OR($D3="A",$D3="H",$D3="HK",$D3="K",$D3="R"),
        //                         N("多肉部分")+((((CD3)/2)^2*PI()-(CE3/2)^2*PI())*((CF3-$O3)/2)+(((CD3)/2)^2*PI()-(($L3+0.3)/2)^2*PI())*((CF3+$O3)/2)+((($L3+0.3)/2)^2*PI()-(($U3)/2)^2*PI())*(($N3-$M3)/2)+((($L3+0.3)/2)^2*PI()-(($R3)/2)^2*PI())*($O3-$N3))/1500+9+
        //                         N("表面粗车")+(($L3+0.3)*PI()*((CF3+$M3)/2)+($U3)*PI()*(($N3-$M3)/2)+(($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI()+($X3-0.2)*PI()*((CF3+$N3)/2))/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*2.2,500*2.2)+12+
        //                         N("表面精车")+((($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI()+($U3)*PI()*(($N3-$M3)/2))/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*0.8,500*0.8)+6+
        //                         N("切断")+IF(CD3>46,0,(CD3)/2.零售1)+10+N("结束"),
        //                 OR($D3="F",$D3="C",$D3="D"),
        //                         N("多肉部分")+((((CD3)/2)^2*PI()-(CE3/2)^2*PI())*((CF3-$O3)/2)+(((CD3)/2)^2*PI()-(($L3+0.3)/2)^2*PI())*((CF3+$O3)/2)+((($L3+0.3)/2)^2*PI()-(($U3)/2)^2*PI())*(($N3-$M3)/2)+((($L3+0.3)/2)^2*PI()-(($R3)/2)^2*PI())*($O3-$N3))/600+9+
        //                         N("表面粗车")+(($L3+0.3)*PI()*((CF3+$M3)/2)+($U3)*PI()*(($N3-$M3)/2)+(($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI()+($X3-0.2)*PI()*((CF3+$N3)/2))/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*1.2,500*1.2)+12+
        //                         N("表面精车")+((($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI()+($U3)*PI()*(($N3-$M3)/2))/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*0.5,500*0.5)+6+
        //                         N("切断")+IF(CD3>46,0,(CD3)/1.零售1)+10+N("结束")))

        String[] materialSizeSplit = materialSize.split("\\*");
        BigDecimal materialOutsideDiameter = new BigDecimal(materialSizeSplit[0]);
        BigDecimal materialLength = new BigDecimal(materialSizeSplit[1]);
        BigDecimal two = new BigDecimal("2");
        // CF - N
        BigDecimal CFjN = materialLength.subtract(hlBandwidth.getBandwidthW());
        // OD + 0.3
        BigDecimal OD03 = OD.add(BigDecimal.valueOf(0.3));
        // CF + N
        BigDecimal CFjjN = materialLength.add(hlBandwidth.getBandwidthW());
        // U
        BigDecimal tpE = null;
        if (ObjectUtils.isNotEmpty(hlTimingPulley.getTpDe())) {
            tpE = new BigDecimal(hlTimingPulley.getTpDe());
        } else {
            tpE = new BigDecimal(hlTimingPulley.getTpE());
        }
        // N - M
        BigDecimal NjM = hlBandwidth.getBandwidthW().subtract(hlBandwidth.getBandwidthA());
        // CF + M
        BigDecimal CFjjM = materialLength.add(hlBandwidth.getBandwidthA());
        // X
        BigDecimal tpMinD = new BigDecimal(hlTimingPulley.getTpMinD());
        // X - 0.2
        BigDecimal Xj02 = tpMinD.subtract(BigDecimal.valueOf(0.2));
        // CF - O
        BigDecimal CFjO = materialLength.subtract(hlBandwidth.getBandwidthL());
        // CF + O
        BigDecimal CFjjO = materialLength.add(hlBandwidth.getBandwidthL());
        // R
        BigDecimal tpD = new BigDecimal(hlTimingPulley.getTpD());
        // O - N
        BigDecimal OjN = hlBandwidth.getBandwidthL().subtract(hlBandwidth.getBandwidthW());


        // π 圆周率
        BigDecimal π = new BigDecimal(Math.PI);
        // ((CD3)/2)^2*PI()
        BigDecimal CD3CD3PI = materialOutsideDiameter.divide(two, 10, RoundingMode.HALF_UP).multiply(materialOutsideDiameter.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // (CE3/2)^2*PI()
        BigDecimal CE3CE3PI = new BigDecimal(0);
        // ((CF3-$N3)/2)
        BigDecimal CF3jN3 = CFjN.divide(two, 10, RoundingMode.HALF_UP);
        // (($L3+0.3)/2)^2*PI()
        BigDecimal L3jj03L3jj03PI = OD03.divide(two, 10, RoundingMode.HALF_UP).multiply(OD03.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // ((CF3+$N3)/2)
        BigDecimal CF3jjN3 = CFjjN.divide(two, 10, RoundingMode.HALF_UP);
        // (($U3)/2)^2*PI()
        BigDecimal U3U3PI = tpE.divide(two, 10, RoundingMode.HALF_UP).multiply(tpE.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // (($N3-$M3)/2))
        BigDecimal N3jM3 = NjM.divide(two, 10, RoundingMode.HALF_UP);

        // ($L3+0.3)*PI()
        BigDecimal L3jj03PI = OD03.multiply(π);
        // ((CF3+$M3)/2)
        BigDecimal CF3jjM3 = CFjjM.divide(two, 10, RoundingMode.HALF_UP);
        // ($U3)*PI()
        BigDecimal U3PI = tpE.multiply(π);
        // (($X3-0.2)/2)^2*PI()
        BigDecimal Xj02Xj02PI = Xj02.divide(two, 10, RoundingMode.HALF_UP).multiply(Xj02.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // ($X3-0.2)*PI()
        BigDecimal Xj02PI = Xj02.multiply(π);
        // OD + tpMinD
        BigDecimal ODjjTpMinD = OD.add(tpMinD);
        // ((CF3-$O3)/2)
        BigDecimal CF3jO3 = CFjO.divide(two, 10, RoundingMode.HALF_UP);
        // ((CF3+$O3)/2)
        BigDecimal CF3jjO3 = CFjjO.divide(two, 10, RoundingMode.HALF_UP);
        // (($R3)/2)^2*PI())
        BigDecimal R3R3PI = tpD.divide(two, 10, RoundingMode.HALF_UP).multiply(tpD.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);

        // 多肉部分
        BigDecimal succulentPart = new BigDecimal(0);

        // 表面粗车
        BigDecimal surfaceRoughTurning = (L3jj03PI.multiply(CF3jjM3)).add(U3PI.multiply(N3jM3)).add(L3jj03L3jj03PI).subtract(Xj02Xj02PI).add(Xj02PI.multiply(CF3jjN3));
        BigDecimal divideConstantTrue = (ODjjTpMinD.divide(two, 10, RoundingMode.HALF_UP)).divide(BigDecimal.valueOf(0.0955), 10, RoundingMode.HALF_UP);

        // 表面精车
        BigDecimal surfaceFinishing = L3jj03L3jj03PI.subtract(Xj02Xj02PI).add(U3PI.multiply(N3jM3));

        // 切断
        BigDecimal cutOff = new BigDecimal(0);

        if (ObjectUtils.equals("A", tpShape)) {

            // 多肉部分
            succulentPart = ((CD3CD3PI.subtract(CE3CE3PI)).multiply(CF3jN3)).add((CD3CD3PI.subtract(L3jj03L3jj03PI)).multiply(CF3jjN3)).add((L3jj03L3jj03PI.subtract(U3U3PI)).multiply(N3jM3));

            if (
                    ObjectUtils.equals("A", materialMark) ||
                            ObjectUtils.equals("H", materialMark) ||
                            ObjectUtils.equals("HK", materialMark) ||
                            ObjectUtils.equals("K", materialMark) ||
                            ObjectUtils.equals("R", materialMark)
            ) {

                succulentPart = succulentPart.divide(BigDecimal.valueOf(1500), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9));

                if (ODjjTpMinD.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                    surfaceRoughTurning = surfaceRoughTurning.divide(divideConstantTrue.multiply(BigDecimal.valueOf(2.2)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(12));
                    surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.8)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                } else {
                    surfaceRoughTurning = surfaceRoughTurning.divide(BigDecimal.valueOf(500 * 2.2), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(12));
                    surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.8), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                }

                if (materialOutsideDiameter.compareTo(BigDecimal.valueOf(46)) <= 0) {
                    cutOff = materialOutsideDiameter.divide(BigDecimal.valueOf(2.1), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(1)).add(BigDecimal.valueOf(10));
                } else {
                    cutOff = cutOff.add(BigDecimal.valueOf(10));
                }

            } else if (
                    ObjectUtils.equals("F", materialMark) ||
                            ObjectUtils.equals("C", materialMark) ||
                            ObjectUtils.equals("D", materialMark)
            ) {

                succulentPart = succulentPart.divide(BigDecimal.valueOf(600), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9));

                if (ODjjTpMinD.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                    surfaceRoughTurning = surfaceRoughTurning.divide(divideConstantTrue.multiply(BigDecimal.valueOf(1.2)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(12));
                    surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.5)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                } else {
                    surfaceRoughTurning = surfaceRoughTurning.divide(BigDecimal.valueOf(500 * 1.2), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(12));
                    surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.5), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                }

                if (materialOutsideDiameter.compareTo(BigDecimal.valueOf(46)) <= 0) {
                    cutOff = materialOutsideDiameter.divide(BigDecimal.valueOf(1.1), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(1)).add(BigDecimal.valueOf(10));
                } else {
                    cutOff = cutOff.add(BigDecimal.valueOf(10));
                }
            } else {
                return new BigDecimal("0");
            }
        } else if (ObjectUtils.equals("B", tpShape) || ObjectUtils.equals("K", tpShape)) {

            // 多肉部分
            succulentPart = ((CD3CD3PI.subtract(CE3CE3PI)).multiply(CF3jO3)).add((CD3CD3PI.subtract(L3jj03L3jj03PI)).multiply(CF3jjO3)).add((L3jj03L3jj03PI.subtract(U3U3PI)).multiply(N3jM3)).add((L3jj03L3jj03PI.subtract(R3R3PI)).multiply(OjN));

            if (
                    ObjectUtils.equals("A", materialMark) ||
                            ObjectUtils.equals("H", materialMark) ||
                            ObjectUtils.equals("HK", materialMark) ||
                            ObjectUtils.equals("K", materialMark) ||
                            ObjectUtils.equals("R", materialMark)
            ) {

                succulentPart = succulentPart.divide(BigDecimal.valueOf(1500), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9));

                if (ODjjTpMinD.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                    surfaceRoughTurning = surfaceRoughTurning.divide(divideConstantTrue.multiply(BigDecimal.valueOf(2.2)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(12));
                    surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.8)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                } else {
                    surfaceRoughTurning = surfaceRoughTurning.divide(BigDecimal.valueOf(500 * 2.2), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(12));
                    surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.8), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                }

                if (materialOutsideDiameter.compareTo(BigDecimal.valueOf(46)) <= 0) {
                    cutOff = materialOutsideDiameter.divide(BigDecimal.valueOf(2.1), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(1)).add(BigDecimal.valueOf(10));
                } else {
                    cutOff = cutOff.add(BigDecimal.valueOf(10));
                }

            } else if (
                    ObjectUtils.equals("F", materialMark) ||
                            ObjectUtils.equals("C", materialMark) ||
                            ObjectUtils.equals("D", materialMark)
            ) {

                succulentPart = succulentPart.divide(BigDecimal.valueOf(600), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9));

                if (ODjjTpMinD.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                    surfaceRoughTurning = surfaceRoughTurning.divide(divideConstantTrue.multiply(BigDecimal.valueOf(1.2)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(12));
                    surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.5)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                } else {
                    surfaceRoughTurning = surfaceRoughTurning.divide(BigDecimal.valueOf(500 * 1.2), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(12));
                    surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.5), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                }

                if (materialOutsideDiameter.compareTo(BigDecimal.valueOf(46)) <= 0) {
                    cutOff = materialOutsideDiameter.divide(BigDecimal.valueOf(1.1), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(1)).add(BigDecimal.valueOf(10));
                } else {
                    cutOff = cutOff.add(BigDecimal.valueOf(10));
                }
            } else {
                return new BigDecimal("0");
            }
        } else {
            return new BigDecimal("0");
        }
        return succulentPart.add(surfaceRoughTurning).add(surfaceFinishing).add(cutOff);
    }

    /**
     * 车B时间
     *
     * @param materialSize 同步轮材料尺寸
     * @param OD 同步轮成品的信息:   O.D.
     * @param hlBandwidth 齿形带宽表
     * @param hlTimingPulley 同步轮表
     * @param tpShape 同步轮形状
     * @param materialMark 同步轮材质
     * @return 结果
     */
    public BigDecimal resultVehicleBTime(String materialSize, BigDecimal OD, HlBandwidth hlBandwidth,
                                         HlTimingPulley hlTimingPulley, String tpShape, String materialMark) {

        // =IFS(
        //         $H3="A",
        //         IFS(
        //                 OR($D3="A",$D3="H",$D3="HK",$D3="K",$D3="R"),
        //                         N("多肉部分")+(((($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI())*((CF3-$N3)/2)+((($L3+0.3)/2)^2*PI()-(($U3)/2)^2*PI())*(($N3-$M3)/2))/1500+6+
        //                         N("表面粗车")+(0)/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*2.2,500*2.2)+0+
        //                         N("表面精车")+((($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI()+($X3)*PI()*($N3)+($U3)*PI()*(($N3-$M3)/2))/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*0.8,500*0.8)+9+10+
        //                         N("结束"),
        //                 OR($D3="F",$D3="C",$D3="D"),
        //                         N("多肉部分")+(((($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI())*((CF3-$N3)/2)+((($L3+0.3)/2)^2*PI()-(($U3)/2)^2*PI())*(($N3-$M3)/2))/600+6+
        //                         N("表面粗车")+(0)/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*1.2,500*1.2)+0+
        //                         N("表面精车")+((($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI()+($X3)*PI()*($N3)+($U3)*PI()*(($N3-$M3)/2))/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*0.5,500*0.5)+9+10+
        //                         N("结束")),
        //         OR($H3="B",$H3="K"),
        //         IFS(
        //                 OR($D3="A",$D3="H",$D3="HK",$D3="K",$D3="R"),
        //                         N("多肉部分")+(((($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI())*((CF3-$N3)/2)+((($L3+0.3)/2)^2*PI()-(($U3)/2)^2*PI())*(($N3-$M3)/2))/1500+6+
        //                         N("表面粗车")+(0)/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*2.2,500*2.2)+0+
        //                         N("表面精车")+((($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI()+($X3)*PI()*($N3)+($U3)*PI()*(($N3-$M3)/2))/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*0.8,500*0.8)+9+10+
        //                         N("结束"),
        //                 OR($D3="F",$D3="C",$D3="D"),
        //                         N("多肉部分")+(((($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI())*((CF3-$N3)/2)+((($L3+0.3)/2)^2*PI()-(($U3)/2)^2*PI())*(($N3-$M3)/2))/600+6+
        //                         N("表面粗车")+(0)/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*1.2,500*1.2)+0+
        //                         N("表面精车")+((($L3+0.3)/2)^2*PI()-(($X3-0.2)/2)^2*PI()+($X3)*PI()*($N3)+($U3)*PI()*(($N3-$M3)/2))/IF(($L3+$X3)<95.5,($L3+$X3)/2/0.0955*0.5,500*0.5)+9+10+
        //                         N("结束")))

        String[] materialSizeSplit = materialSize.split("\\*");
        BigDecimal materialOutsideDiameter = new BigDecimal(materialSizeSplit[0]);
        BigDecimal materialLength = new BigDecimal(materialSizeSplit[1]);
        BigDecimal two = new BigDecimal("2");
        // CF - N
        BigDecimal CFjN = materialLength.subtract(hlBandwidth.getBandwidthW());
        // OD + 0.3
        BigDecimal OD03 = OD.add(BigDecimal.valueOf(0.3));
        // CF + N
        BigDecimal CFjjN = materialLength.add(hlBandwidth.getBandwidthW());
        // U
        BigDecimal tpE = null;
        if (ObjectUtils.isNotEmpty(hlTimingPulley.getTpDe())) {
            tpE = new BigDecimal(hlTimingPulley.getTpDe());
        } else {
            tpE = new BigDecimal(hlTimingPulley.getTpE());
        }
        // N - M
        BigDecimal NjM = hlBandwidth.getBandwidthW().subtract(hlBandwidth.getBandwidthA());
        // CF + M
        BigDecimal CFjjM = materialLength.add(hlBandwidth.getBandwidthA());
        // X
        BigDecimal tpMinD = new BigDecimal(hlTimingPulley.getTpMinD());
        // X - 0.2
        BigDecimal Xj02 = tpMinD.subtract(BigDecimal.valueOf(0.2));
        // CF - O
        BigDecimal CFjO = materialLength.subtract(hlBandwidth.getBandwidthL());
        // CF + O
        BigDecimal CFjjO = materialLength.add(hlBandwidth.getBandwidthL());
        // R
        BigDecimal tpD = new BigDecimal(hlTimingPulley.getTpD());
        // O - N
        BigDecimal OjN = hlBandwidth.getBandwidthL().subtract(hlBandwidth.getBandwidthW());


        // π 圆周率
        BigDecimal π = new BigDecimal(Math.PI);
        // ((CD3)/2)^2*PI()
        BigDecimal CD3CD3PI = materialOutsideDiameter.divide(two, 10, RoundingMode.HALF_UP).multiply(materialOutsideDiameter.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // (CE3/2)^2*PI()
        BigDecimal CE3CE3PI = new BigDecimal(0);
        // ((CF3-$N3)/2)
        BigDecimal CF3jN3 = CFjN.divide(two, 10, RoundingMode.HALF_UP);
        // (($L3+0.3)/2)^2*PI()
        BigDecimal L3jj03L3jj03PI = OD03.divide(two, 10, RoundingMode.HALF_UP).multiply(OD03.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // ((CF3+$N3)/2)
        BigDecimal CF3jjN3 = CFjjN.divide(two, 10, RoundingMode.HALF_UP);
        // (($U3)/2)^2*PI()
        BigDecimal U3U3PI = tpE.divide(two, 10, RoundingMode.HALF_UP).multiply(tpE.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // (($N3-$M3)/2))
        BigDecimal N3jM3 = NjM.divide(two, 10, RoundingMode.HALF_UP);

        // ($L3+0.3)*PI()
        BigDecimal L3jj03PI = OD03.multiply(π);
        // ((CF3+$M3)/2)
        BigDecimal CF3jjM3 = CFjjM.divide(two, 10, RoundingMode.HALF_UP);
        // ($U3)*PI()
        BigDecimal U3PI = tpE.multiply(π);
        // (($X3-0.2)/2)^2*PI()
        BigDecimal Xj02Xj02PI = Xj02.divide(two, 10, RoundingMode.HALF_UP).multiply(Xj02.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // ($X3-0.2)*PI()
        BigDecimal Xj02PI = Xj02.multiply(π);
        // OD + tpMinD
        BigDecimal ODjjTpMinD = OD.add(tpMinD);
        // ((CF3-$O3)/2)
        BigDecimal CF3jO3 = CFjO.divide(two, 10, RoundingMode.HALF_UP);
        // ((CF3+$O3)/2)
        BigDecimal CF3jjO3 = CFjjO.divide(two, 10, RoundingMode.HALF_UP);
        // (($R3)/2)^2*PI())
        BigDecimal R3R3PI = tpD.divide(two, 10, RoundingMode.HALF_UP).multiply(tpD.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // ($X3)*PI()
        BigDecimal X3PI = tpMinD.multiply(π);

        // 多肉部分
        BigDecimal succulentPart = new BigDecimal(0);

        // 表面粗车
        BigDecimal surfaceRoughTurning = new BigDecimal(0);

        BigDecimal divideConstantTrue = (ODjjTpMinD.divide(two, 10, RoundingMode.HALF_UP)).divide(BigDecimal.valueOf(0.0955), 10, RoundingMode.HALF_UP);

        // 表面精车
        BigDecimal surfaceFinishing = L3jj03L3jj03PI.subtract(Xj02Xj02PI).add(X3PI.multiply(hlBandwidth.getBandwidthW())).add(U3PI.multiply(N3jM3));

        // 切断
        BigDecimal cutOff = new BigDecimal(0);

        if (ObjectUtils.equals("A", tpShape)) {

            // 多肉部分
            succulentPart = ((CD3CD3PI.subtract(Xj02Xj02PI)).multiply(CF3jN3)).add((L3jj03L3jj03PI.subtract(U3U3PI)).multiply(N3jM3));

            if (
                    ObjectUtils.equals("A", materialMark) ||
                            ObjectUtils.equals("H", materialMark) ||
                            ObjectUtils.equals("HK", materialMark) ||
                            ObjectUtils.equals("K", materialMark) ||
                            ObjectUtils.equals("R", materialMark)
            ) {

                succulentPart = succulentPart.divide(BigDecimal.valueOf(1500), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));

                if (ODjjTpMinD.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                    surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.8)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9)).add(BigDecimal.valueOf(10));
                } else {
                    surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.8), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9)).add(BigDecimal.valueOf(10));
                }

            } else if (
                    ObjectUtils.equals("F", materialMark) ||
                            ObjectUtils.equals("C", materialMark) ||
                            ObjectUtils.equals("D", materialMark)
            ) {

                succulentPart = succulentPart.divide(BigDecimal.valueOf(600), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));

                if (ODjjTpMinD.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                    surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.5)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9)).add(BigDecimal.valueOf(10));
                } else {
                    surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.5), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9)).add(BigDecimal.valueOf(10));
                }
            } else {
                return new BigDecimal("0");
            }
        } else if (ObjectUtils.equals("B", tpShape) || ObjectUtils.equals("K", tpShape)) {

            // 多肉部分
            succulentPart = ((CD3CD3PI.subtract(Xj02Xj02PI)).multiply(CF3jN3)).add((L3jj03L3jj03PI.subtract(U3U3PI)).multiply(N3jM3));

            if (
                    ObjectUtils.equals("A", materialMark) ||
                            ObjectUtils.equals("H", materialMark) ||
                            ObjectUtils.equals("HK", materialMark) ||
                            ObjectUtils.equals("K", materialMark) ||
                            ObjectUtils.equals("R", materialMark)
            ) {

                succulentPart = succulentPart.divide(BigDecimal.valueOf(1500), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));

                if (ODjjTpMinD.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                    surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.8)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9)).add(BigDecimal.valueOf(10));
                } else {
                    surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.8), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9)).add(BigDecimal.valueOf(10));
                }

            } else if (
                    ObjectUtils.equals("F", materialMark) ||
                            ObjectUtils.equals("C", materialMark) ||
                            ObjectUtils.equals("D", materialMark)
            ) {

                succulentPart = succulentPart.divide(BigDecimal.valueOf(600), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));

                if (ODjjTpMinD.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                    surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.5)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9)).add(BigDecimal.valueOf(10));
                } else {
                    surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.5), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9)).add(BigDecimal.valueOf(10));
                }
            } else {
                return new BigDecimal("0");
            }
        } else {
            return new BigDecimal("0");
        }
        return succulentPart.add(surfaceRoughTurning).add(surfaceFinishing).add(cutOff);
    }

    /**
     * 车床费用
     *
     * @param vehicleATime 车A时间
     * @param vehicleBTime 车B时间
     * @return 结果
     */
    public BigDecimal resultLatheCost(BigDecimal vehicleATime, BigDecimal vehicleBTime) {
        if (vehicleATime.compareTo(BigDecimal.valueOf(0)) == 0) {
            return BigDecimal.valueOf(0);
        }
        return (vehicleATime.divide(BigDecimal.valueOf(3600), 10, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(55))).add(vehicleBTime.divide(BigDecimal.valueOf(3600), 10, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(55)));
    }

    /**
     * 滚齿时间
     *
     * @param hlMaterial 材质表
     * @param teethNum 齿数
     * @param hlBandwidth 齿形带宽表
     * @return 滚齿时间
     */
    public BigDecimal resultHobbingTime(HlMaterial hlMaterial, BigDecimal teethNum, HlBandwidth hlBandwidth) {
        String materialType = hlMaterial.getMaterialType();
        BigDecimal twentyFive = BigDecimal.valueOf(25);
        BigDecimal six = BigDecimal.valueOf(6);
        BigDecimal zeroPointSix = BigDecimal.valueOf(0.6);
        BigDecimal ten = BigDecimal.valueOf(10);
        BigDecimal zeroPointFour = BigDecimal.valueOf(0.4);

        // 同步轮材质为 铝
        if (ObjectUtils.equals("铝", materialType)) {
            // 公式: 齿数/25  *  [W + (6/0.6)]  + 10
            return teethNum.divide(twentyFive, 10, RoundingMode.HALF_UP)
                    .multiply(hlBandwidth.getBandwidthW().add(six.divide(zeroPointSix, 10, RoundingMode.HALF_UP))).add(ten);

        } else if (ObjectUtils.equals("钢", materialType)) {
            // 公式: 齿数/10  *  [W + (6/0.4)]  + 10
            return teethNum.divide(ten, 10, RoundingMode.HALF_UP)
                    .multiply(hlBandwidth.getBandwidthW().add(six.divide(zeroPointFour, 10, RoundingMode.HALF_UP))).add(ten);
        }
        return BigDecimal.valueOf(0);
    }

    /**
     * 滚齿费用
     *
     * @param tooth 齿形
     * @param teethNum 齿数
     * @param hobbingTime 滚齿时间
     * @return 结果
     */
    public BigDecimal resultHobbingCost(String tooth, BigDecimal teethNum, BigDecimal hobbingTime) {
        BigDecimal min = BigDecimal.valueOf(3600);
        BigDecimal oneHundredAndFifteen = new BigDecimal(115);
        BigDecimal eightyFive = new BigDecimal(85);
        int teethNumber = teethNum.intValue();
        if (
                (ObjectUtils.equals("H3M", tooth) && teethNumber >= 81) ||
                        (ObjectUtils.equals("H5M", tooth) && teethNumber >= 81) ||
                        (ObjectUtils.equals("H8M", tooth)) ||
                        (ObjectUtils.equals("S3M", tooth) && teethNumber >= 60) ||
                        (ObjectUtils.equals("S5M", tooth) && teethNumber >= 60) ||
                        (ObjectUtils.equals("S8M", tooth) && teethNumber >= 47) ||
                        (ObjectUtils.equals("T5", tooth) && teethNumber >= 81) ||
                        (ObjectUtils.equals("T10", tooth) && teethNumber >= 31) ||
                        (ObjectUtils.equals("XL", tooth) && teethNumber >= 81) ||
                        (ObjectUtils.equals("L", tooth) && teethNumber >= 31) ||
                        (ObjectUtils.equals("H", tooth) && teethNumber >= 31)
        ) {
            return hobbingTime.divide(min, 10, RoundingMode.HALF_UP).multiply(oneHundredAndFifteen);
        } else {
            return hobbingTime.divide(min, 6, RoundingMode.HALF_UP).multiply(eightyFive);
        }
    }

    /**
     * 攻牙时间
     *
     * @param tpShape      同步轮形状
     * @param hlTimingPulley 同步轮
     * @return 攻牙时间
     */
    public BigDecimal resultAttackTeethTime(String tpShape, HlTimingPulley hlTimingPulley) {
        BigDecimal tpOd = new BigDecimal(hlTimingPulley.getTpOd());
        BigDecimal tpMinD = new BigDecimal(hlTimingPulley.getTpMinD());
        BigDecimal tpD = new BigDecimal(hlTimingPulley.getTpD());
        BigDecimal two = new BigDecimal("2");
        BigDecimal zeroPointFour = new BigDecimal("0.4");
        BigDecimal five = new BigDecimal("5");
        BigDecimal fifteen = new BigDecimal("15");
        // 同步轮形状为 A
        if (ObjectUtils.equals("A", tpShape)) {
            // 公式: (同步轮形状/2 - minD/2)/0.4 + 5 + 15
            return (tpOd.divide(two, 10, RoundingMode.HALF_UP)).subtract(tpMinD.divide(two, 10, RoundingMode.HALF_UP))
                    .divide(zeroPointFour, 10, RoundingMode.HALF_UP).add(five).add(fifteen);
        } else {
            // 公式: (D/2 - minD/2)/0.4 + 5 + 15
            return (tpD.divide(two, 10, RoundingMode.HALF_UP)).subtract(tpMinD.divide(two, 10, RoundingMode.HALF_UP))
                    .divide(zeroPointFour, 10, RoundingMode.HALF_UP).add(five).add(fifteen);
        }
    }

    /**
     * 攻牙费用
     *
     * @param attackTeethTime 攻牙时间
     * @return 结果
     */
    public BigDecimal resultAttackTeethCost(BigDecimal attackTeethTime) {
        return attackTeethTime.divide(BigDecimal.valueOf(3600), 10, RoundingMode.HALF_UP).multiply(new BigDecimal(55));
    }

    /**
     * 拉键槽时间
     *
     * @param tpShape   同步轮形状
     * @param hlBandwidth 齿形带宽表
     * @return 拉键槽时间
     */
    public BigDecimal resultPullingKeyGrooveTime(String tpShape, HlBandwidth hlBandwidth, String tpAxleHoleType, BigDecimal d) {
        String keywayName = "";
        BigDecimal keyway = new BigDecimal("0");

        if ("N".equals(tpAxleHoleType)) {
            keywayName = "N" + d;
        } else if ("C".equals(tpAxleHoleType)) {
            keywayName = "C" + d;
        } else {
            return new BigDecimal("0");
        }
        // 查询键槽表
        HlKeyway hlKeyway = hlKeywayService.selectOne(keywayName);
        if (ObjectUtils.isNotEmpty(hlKeyway)) {
            String keywayB = hlKeyway.getKeywayB();
            int intKeywayB = Integer.parseInt(keywayB);
            if (intKeywayB == 3 || intKeywayB == 4 || intKeywayB == 5) {
                keyway = BigDecimal.valueOf(1);
            } else if (intKeywayB == 6 || intKeywayB == 8) {
                keyway = BigDecimal.valueOf(1.5);
            } else if (intKeywayB == 10 || intKeywayB == 12) {
                keyway = BigDecimal.valueOf(2);
            } else if (intKeywayB > 12) {
                keyway = BigDecimal.valueOf(2.5);
            }
        }

        BigDecimal shape = BigDecimal.valueOf(0);
        if (ObjectUtils.equals("A", tpShape)) {
            if (hlBandwidth.getBandwidthW().compareTo(BigDecimal.valueOf(10)) < 0) {
                shape = BigDecimal.valueOf(25);
            } else {
                shape = hlBandwidth.getBandwidthW().subtract(BigDecimal.valueOf(10)).add(BigDecimal.valueOf(25));
            }
        } else if (ObjectUtils.equals("B", tpShape) || ObjectUtils.equals("K", tpShape)) {
            if (hlBandwidth.getBandwidthL().compareTo(BigDecimal.valueOf(10)) < 0) {
                shape = BigDecimal.valueOf(25);
            } else {
                shape = hlBandwidth.getBandwidthL().subtract(BigDecimal.valueOf(10)).add(BigDecimal.valueOf(25));
            }
        }

        return keyway.multiply(BigDecimal.valueOf(2)).multiply(shape);

        /*BigDecimal sixty = new BigDecimal("60");
        BigDecimal eighty = new BigDecimal("80");
        BigDecimal five = new BigDecimal("5");
        BigDecimal fifteen = new BigDecimal("15");
        // 同步轮形状为 A
        if (ObjectUtils.equals("A", tpShape)) {
            // 公式: 60/[(80/W) 向上取整数] + 5 + 15
            return sixty.divide(eighty.divide(hlBandwidth.getBandwidthW(), 10, RoundingMode.HALF_UP).setScale(0, RoundingMode.UP), 10, RoundingMode.HALF_UP).add(five).add(fifteen);
        } else if (ObjectUtils.equals("B", tpShape) || ObjectUtils.equals("K", tpShape)) {
            // 公式: 60/[(80/L) 向上取整数] + 5 + 15
            return sixty.divide(eighty.divide(hlBandwidth.getBandwidthL(), 10, RoundingMode.HALF_UP).setScale(0, RoundingMode.UP), 10, RoundingMode.HALF_UP).add(five).add(fifteen);
        }*/
        // return new BigDecimal("0");
    }

    /**
     * 拉键槽费用
     *
     * @param pullingKeyGrooveTime 拉键槽时间
     * @return 结果
     */
    public BigDecimal resultPullingKeyGrooveCost(BigDecimal pullingKeyGrooveTime) {
        return pullingKeyGrooveTime.divide(BigDecimal.valueOf(3600), 6, RoundingMode.HALF_UP).multiply(new BigDecimal(35));
    }

    /**
     * 压挡圈时间
     *
     * @return 结果
     */
    public BigDecimal resultPressureRetainingRingTime() {
        return new BigDecimal("20");
    }

    /**
     * 压挡圈费用
     *
     * @param pressureRetainingRingTime 压挡圈时间
     * @return 结果
     */
    public BigDecimal resultPressureRetainingRingCost(BigDecimal pressureRetainingRingTime) {
        return pressureRetainingRingTime.divide(BigDecimal.valueOf(3600), 6, RoundingMode.HALF_UP).multiply(new BigDecimal(25));
    }

    /**
     * 表面处理费用
     *
     * @param hlMaterial 材质表
     * @param finishedMass 同步轮成品的信息:   重量
     * @return 结果
     */
    public BigDecimal resultSurfaceTreatmentCost(HlMaterial hlMaterial, BigDecimal finishedMass) {
        String materialMark = hlMaterial.getMaterialMark();
        if (ObjectUtils.equals("A", materialMark) || ObjectUtils.equals("F", materialMark) || ObjectUtils.equals("S", materialMark)) {
            return new BigDecimal("0");
        } else if (ObjectUtils.equals("H", materialMark)) {
            return finishedMass.multiply(BigDecimal.valueOf(8)).add(BigDecimal.valueOf(0.2));
        } else if (ObjectUtils.equals("HK", materialMark)) {
            return finishedMass.multiply(BigDecimal.valueOf(12)).add(BigDecimal.valueOf(0.2));
        } else if (ObjectUtils.equals("K", materialMark)) {
            return finishedMass.multiply(BigDecimal.valueOf(30)).add(BigDecimal.valueOf(0.2));
        } else if (ObjectUtils.equals("R", materialMark)) {
            return finishedMass.multiply(BigDecimal.valueOf(9)).add(BigDecimal.valueOf(0.2));
        } else if (ObjectUtils.equals("C", materialMark)) {
            return finishedMass.multiply(BigDecimal.valueOf(3)).add(BigDecimal.valueOf(0.2));
        } else if (ObjectUtils.equals("D", materialMark)) {
            return finishedMass.multiply(BigDecimal.valueOf(7)).add(BigDecimal.valueOf(0.2));
        }
        return new BigDecimal("0");
    }

    /**
     * 挡圈费用
     *
     * @param materialMark 同步轮材质
     * @param tooth 齿形
     * @param hlTimingPulley 同步轮表
     * @param tpShape 同步轮形状
     * @return 结果
     */
    public BigDecimal resultFlangeCost(String materialMark, String tooth, HlTimingPulley hlTimingPulley, String tpShape) {
        if (ObjectUtils.isEmpty(hlTimingPulley.getTpF())) {
            return new BigDecimal("0");
        }

        // 同步轮F
        BigDecimal tpF = new BigDecimal(hlTimingPulley.getTpF());
        HlFlange hlFlange = new HlFlange();
        List<HlFlange> hlFlangeList = hlFlangeService.selectHlFlangeList(hlFlange);
        for (int i = 0; i < hlFlangeList.size(); i++) {
            if (i == hlFlangeList.size() - 1) {
                hlFlange =  hlFlangeList.get(i);
                break;
            } else {
                BigDecimal start = new BigDecimal(hlFlangeList.get(i).getFlangeOutsideDiameter());
                BigDecimal end = new BigDecimal(hlFlangeList.get(i + 1).getFlangeOutsideDiameter());
                if (tpF.compareTo(start) >= 0 && tpF.compareTo(end) < 0) {
                    hlFlange = hlFlangeList.get(i);
                    break;
                }
            }
        }
        if (ObjectUtils.isEmpty(hlFlange)) {
            hlFlange = hlFlangeList.get(0);
        }

        // 对应Excel W 即 t
        BigDecimal tpT = new BigDecimal(hlTimingPulley.getTpT());

        BigDecimal constant = new BigDecimal("0");

        if (tpT.compareTo(BigDecimal.valueOf(1.4)) < 0) {
            if (
                    ObjectUtils.equals("H", materialMark) ||
                            ObjectUtils.equals("HK", materialMark) ||
                            ObjectUtils.equals("K", materialMark) ||
                            ObjectUtils.equals("S", materialMark)

            ) {
                constant = new BigDecimal(hlFlange.getOneTwoAluminumAlloy());
            } else if (
                    ObjectUtils.equals("A", materialMark) ||
                            ObjectUtils.equals("R", materialMark) ||
                            ObjectUtils.equals("F", materialMark) ||
                            ObjectUtils.equals("C", materialMark) ||
                            ObjectUtils.equals("D", materialMark)
            ) {
                constant = new BigDecimal(hlFlange.getOneTwoIronNickelPlating());
            }
        } else if (tpT.compareTo(BigDecimal.valueOf(1.4)) >= 0 && tpT.compareTo(BigDecimal.valueOf(1.8)) < 0) {
            if (
                    ObjectUtils.equals("H", materialMark) ||
                            ObjectUtils.equals("HK", materialMark) ||
                            ObjectUtils.equals("K", materialMark) ||
                            ObjectUtils.equals("S", materialMark)

            ) {
                constant = new BigDecimal(hlFlange.getOneFiveAluminumAlloy());
            } else if (
                    ObjectUtils.equals("A", materialMark) ||
                            ObjectUtils.equals("R", materialMark) ||
                            ObjectUtils.equals("F", materialMark) ||
                            ObjectUtils.equals("C", materialMark) ||
                            ObjectUtils.equals("D", materialMark)
            ) {
                constant = new BigDecimal(hlFlange.getOneFiveIronNickelPlating());
            }
        } else if (tpT.compareTo(BigDecimal.valueOf(1.8)) >= 0 && tpT.compareTo(BigDecimal.valueOf(2.3)) < 0) {
            if (
                    ObjectUtils.equals("H", materialMark) ||
                            ObjectUtils.equals("HK", materialMark) ||
                            ObjectUtils.equals("K", materialMark) ||
                            ObjectUtils.equals("S", materialMark)

            ) {
                constant = new BigDecimal(hlFlange.getTwoAluminumAlloy());
            } else if (
                    ObjectUtils.equals("A", materialMark) ||
                            ObjectUtils.equals("R", materialMark) ||
                            ObjectUtils.equals("F", materialMark) ||
                            ObjectUtils.equals("C", materialMark) ||
                            ObjectUtils.equals("D", materialMark)
            ) {
                constant = new BigDecimal(hlFlange.getTwoIronNickelPlating());
            }
        }

        if (ObjectUtils.equals("K", tpShape)) {
            return constant.multiply(BigDecimal.valueOf(1)).add(BigDecimal.valueOf(0.8));
        } else {
            return constant.multiply(BigDecimal.valueOf(2));
        }
    }

    /**
     * 螺丝费用
     *
     * @param tooth 齿形
     * @param d 输入商品编码的 d 内孔直径
     * @return 结果
     */
    public BigDecimal resultScrewCost(String tooth, BigDecimal d) {
        HlScrew screw = new HlScrew();
        screw.setScrewTooth(tooth);
        List<HlScrew> hlScrewList = hlScrewService.selectHlScrewList(screw);
        if (ObjectUtils.isEmpty(hlScrewList)) {
            return new BigDecimal("0");
        }

        // 使用 Arrays.sort() 方法进行排序
        hlScrewList.sort(new Comparator<HlScrew>() {
            @Override
            public int compare(HlScrew o1, HlScrew o2) {
                // 将 String 转换为 Double，然后进行比较
                BigDecimal d1 = new BigDecimal(o1.getScrewTpd());
                BigDecimal d2 = new BigDecimal(o2.getScrewTpd());
                return d1.compareTo(d2);
            }
        });

        // d 内孔直径
        for (int i = 0; i < hlScrewList.size(); i++) {
            BigDecimal screwTpd = new BigDecimal(hlScrewList.get(i).getScrewTpd());

            if (i == hlScrewList.size() - 1) {
                if (d.compareTo(screwTpd) >= 0) {
                    return new BigDecimal(hlScrewList.get(i).getScrewPrice()).multiply(BigDecimal.valueOf(2));
                } else {
                    return new BigDecimal("0");
                }
            } else {
                BigDecimal belowScrewTpd = new BigDecimal(hlScrewList.get(i + 1).getScrewTpd());
                if (d.compareTo(screwTpd) >= 0 && d.compareTo(belowScrewTpd) < 0) {
                    return new BigDecimal(hlScrewList.get(i).getScrewPrice()).multiply(BigDecimal.valueOf(2));
                }
            }
        }
        return new BigDecimal("0");
    }

    /**
     * 装配费用
     *
     * @return 结果
     */
    public BigDecimal resultAssembleCost() {
        return new BigDecimal("0.2");
    }

    /**
     * 包装费用
     *
     * @param OD 同步轮直径
     * @return 结果
     */
    public BigDecimal resultPackageCost(BigDecimal OD) {
        return (OD.multiply(new BigDecimal(Math.PI).multiply(BigDecimal.valueOf(0.001)))).add(BigDecimal.valueOf(0.05));
    }

    /**
     * 物流费用
     *
     * @param finishedMass 同步轮成品的信息:   重量
     * @return 结果
     */


    public BigDecimal resultLogisticsCost(BigDecimal finishedMass) {
        return (finishedMass.multiply(BigDecimal.valueOf(1.5))).add(BigDecimal.valueOf(0.1));
    }

    /**
     * 额外成本
     */
    public BigDecimal resultAdditionalCost(HlTimingPulley hlTimingPulley, String materialMark, BigDecimal bearingCost, String tpShape) {
        BigDecimal D = new BigDecimal("0");
        BigDecimal E = new BigDecimal("0");
        BigDecimal F = new BigDecimal("0");
        if (
                ObjectUtils.equals("K", materialMark) ||
                        ObjectUtils.equals("R", materialMark)
        ) {
            E = BigDecimal.valueOf(80);
        } else if (ObjectUtils.equals("S", materialMark)) {
            E = BigDecimal.valueOf(10);
        }

        if ("TP".equals(hlTimingPulley.getTpType())) {
            if ("A".equals(tpShape)) {
                D = new BigDecimal(hlTimingPulley.getTpShareA());
            } else if ("B".equals(tpShape) || "K".equals(tpShape)) {
                D = new BigDecimal(hlTimingPulley.getTpShareB());
            } else {
                D = new BigDecimal(150);
            }
            return D.add(E);
        } else if ("IG".equals(hlTimingPulley.getTpType())) {
            D = new BigDecimal(hlTimingPulley.getTpShareA());
            if (bearingCost.compareTo(BigDecimal.valueOf(0)) == 0) {
                F = BigDecimal.valueOf(10);
            }
            return D.add(E).add(F);
        } else {
            return new BigDecimal(150);
        }
    }

    /**
     * 改孔时间
     *
     * @param hlTimingPulley 同步轮表
     * @param d 输入商品编码的 d 内孔直径
     * @param materialMark 同步轮材质
     * @param tpShape 同步轮形状
     * @param hlBandwidth 齿形带宽表
     * @param OD 同步轮成品的信息:   重量
     * @return 结果
     */
    public BigDecimal resultHoleModificationTime(HlTimingPulley hlTimingPulley, BigDecimal d, String materialMark,
                                                 String tpShape, HlBandwidth hlBandwidth, BigDecimal OD) {
        BigDecimal two = new BigDecimal("2");
        // Y
        BigDecimal tpMinD = new BigDecimal(hlTimingPulley.getTpMinD());
        BigDecimal tpMaxD = new BigDecimal(hlTimingPulley.getTpMaxD());

        // π 圆周率
        BigDecimal π = new BigDecimal(Math.PI);
        // L + X
        BigDecimal ODjjTpMinD = OD.add(tpMinD);

        // ($J3/2)^2*PI()
        BigDecimal J3J3PI = d.divide(two, 10, RoundingMode.HALF_UP).multiply(d.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);

        // ($Y448/2)^2*PI()
        BigDecimal Y3Y3PI = tpMaxD.divide(two, 10, RoundingMode.HALF_UP).multiply(tpMaxD.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // ($X3/2)^2*PI()
        BigDecimal X3X3PI = tpMinD.divide(two, 10, RoundingMode.HALF_UP).multiply(tpMinD.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);

        // 多肉部分
        BigDecimal succulentPart = new BigDecimal(0);

        // 表面粗车
        BigDecimal surfaceRoughTurning = new BigDecimal(0);
        BigDecimal divideConstantTrue = (ODjjTpMinD.divide(two, 10, RoundingMode.HALF_UP)).divide(BigDecimal.valueOf(0.0955), 10, RoundingMode.HALF_UP);

        // 表面精车
        BigDecimal surfaceFinishing = new BigDecimal(0);;

        // 切断
        BigDecimal cutOff = new BigDecimal(0);

        if (ObjectUtils.equals("A", tpShape)) {

            surfaceFinishing = (Y3Y3PI.subtract(X3X3PI)).multiply(hlBandwidth.getBandwidthW());

            if (
                    ObjectUtils.equals("A", materialMark) ||
                            ObjectUtils.equals("H", materialMark) ||
                            ObjectUtils.equals("HK", materialMark) ||
                            ObjectUtils.equals("K", materialMark) ||
                            ObjectUtils.equals("R", materialMark)
            ) {
                if (ODjjTpMinD.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                    surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(1.2)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                } else {
                    surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 1.2), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                }
            } else if (
                    ObjectUtils.equals("F", materialMark) ||
                            ObjectUtils.equals("C", materialMark) ||
                            ObjectUtils.equals("D", materialMark)
            ) {

                succulentPart = (Y3Y3PI.subtract(X3X3PI)).multiply(hlBandwidth.getBandwidthW()).divide(BigDecimal.valueOf(600), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9));

                if (ODjjTpMinD.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                    surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.5)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                } else {
                    surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.5), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                }
            } else {
                return new BigDecimal("0");
            }
        }
        else if (ObjectUtils.equals("B", tpShape) || ObjectUtils.equals("K", tpShape)) {

            surfaceFinishing = (Y3Y3PI.subtract(X3X3PI)).multiply(hlBandwidth.getBandwidthL());

            if (
                    ObjectUtils.equals("A", materialMark) ||
                            ObjectUtils.equals("H", materialMark) ||
                            ObjectUtils.equals("HK", materialMark) ||
                            ObjectUtils.equals("K", materialMark) ||
                            ObjectUtils.equals("R", materialMark)
            ) {
                if (ODjjTpMinD.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                    surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(1.2)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                } else {
                    surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 1.2), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                }
            } else if (
                    ObjectUtils.equals("F", materialMark) ||
                            ObjectUtils.equals("C", materialMark) ||
                            ObjectUtils.equals("D", materialMark)
            ) {

                succulentPart = (Y3Y3PI.subtract(X3X3PI)).multiply(hlBandwidth.getBandwidthL()).divide(BigDecimal.valueOf(600), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9));

                if (ODjjTpMinD.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                    surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.5)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                } else {
                    surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.5), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
                }
            } else {
                return new BigDecimal("0");
            }
        }
        return succulentPart.add(surfaceRoughTurning).add(surfaceFinishing).add(cutOff).add(BigDecimal.valueOf(20));
    }

    /**
     * 改孔费用
     *
     * @param holeModificationTime 改孔时间
     * @param d 输入商品编码的 d 内孔直径
     * @param hlTimingPulley 同步轮表
     * @return 结果
     */
    public BigDecimal resultHoleModificationCost(BigDecimal holeModificationTime, BigDecimal d, HlTimingPulley hlTimingPulley) {
        BigDecimal mind = new BigDecimal(hlTimingPulley.getTpMinD());
        if (d.compareTo(mind) < 0) {
            return BigDecimal.valueOf(0);
        }
        return holeModificationTime.divide(BigDecimal.valueOf(3600), 10, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(45));
    }

    /**
     * 同步轮-材质-齿形带宽 所在类型的最小 mind
     *
     * @param tp 同步轮类型
     * @param materialMark 同步轮材质
     * @param toothBandwidth 同步轮齿形带宽
     * @return 结果
     */
    public BigDecimal tpMind(String tp, String materialMark, String toothBandwidth) {
        LambdaQueryWrapper<HlTimingPulley> hlTimingPulleyWrapper = new LambdaQueryWrapper<>();

        hlTimingPulleyWrapper.eq(HlTimingPulley::getTpType, tp)
                .eq(HlTimingPulley::getTpMaterial, materialMark)
                .eq(HlTimingPulley::getTpToothBandwidth, toothBandwidth)
                .last("limit 1");

        HlTimingPulley hlTimingPulley = hlTimingPulleyMapper.selectOne(hlTimingPulleyWrapper);
        return new BigDecimal(hlTimingPulley.getTpMinD());
    }


    /**
     * 料件成本 materialsPartsCost 加工成本 processCost 合计成本 assessCost
     * 零售价 retailPrice   含税零售 价 taxRetailPrice
     *    1+ 价    num1       含税    1+ 价 taxNum1
     *   10+ 价   num10       含税   10+ 价 taxNum10
     *   20+ 价   num20       含税   20+ 价 taxNum20
     *   50+ 价   num50       含税   50+ 价 taxNum50
     *  100+ 价  num100       含税  100+ 价 taxNum100
     *  500+ 价  num500       含税  500+ 价 taxNum500
     * 1000+ 价 num1000       含税 1000+ 价 taxNum1000
     * 3000+ 价 num3000       含税 3000+ 价 taxNum3000
     *
     * @param tpAxleHoleType 同步轮轴孔类型
     * @param ch    同步轮材料费用 materialPrice
     * @param ci    材料切断 materialCutOff
     * @param cl    车床费用 latheCost
     * @param cn    滚齿费用 hobbingCost
     * @param cp    攻牙费用 attackTeethCost
     * @param cr    拉键槽费用 pullingKeyGrooveCost
     * @param ct    压挡圈费用 pressureRetainingRingCost
     * @param cv    表面处理费用 surfaceTreatmentCost
     * @param cw    挡圈费用 flangeCost
     * @param cx    螺丝费用 screwCost
     * @param cy    装配费用 assembleCost
     * @param cz    包装费用 packageCost
     * @param da    物流费用 logisticsCost
     * @param dc    改孔费用 holeModificationCost
     * @return 结果
     */
    public HashMap<String, BigDecimal> resultCostMap(String tpAxleHoleType, BigDecimal ch, BigDecimal ci,
                                                     BigDecimal cw, BigDecimal cv, BigDecimal da,
                                                     BigDecimal cl, BigDecimal cn, BigDecimal ct,
                                                     BigDecimal cz, BigDecimal cy, BigDecimal cx,
                                                     BigDecimal cp, BigDecimal cr, BigDecimal dc,
                                                     BigDecimal additionalCost) {

        HashMap<String, BigDecimal> costMap = new HashMap<>();
        BigDecimal materialsPartsCost = new BigDecimal("0");
        BigDecimal processCost = new BigDecimal("0");
        BigDecimal assessCost = new BigDecimal("0");
        BigDecimal retailPrice = new BigDecimal("0");
        BigDecimal taxRetailPrice = new BigDecimal("0");
        BigDecimal num1 = new BigDecimal("0");
        BigDecimal num2 = new BigDecimal("0");
        BigDecimal num3 = new BigDecimal("0");
        BigDecimal num4 = new BigDecimal("0");
        BigDecimal num5 = new BigDecimal("0");
        BigDecimal num10 = new BigDecimal("0");
        BigDecimal num20 = new BigDecimal("0");
        BigDecimal num50 = new BigDecimal("0");
        BigDecimal num100 = new BigDecimal("0");
        BigDecimal num500 = new BigDecimal("0");
        BigDecimal num1000 = new BigDecimal("0");
        BigDecimal num3000 = new BigDecimal("0");
        BigDecimal taxNum1 = new BigDecimal("0");
        BigDecimal taxNum2 = new BigDecimal("0");
        BigDecimal taxNum3 = new BigDecimal("0");
        BigDecimal taxNum4 = new BigDecimal("0");
        BigDecimal taxNum5 = new BigDecimal("0");
        BigDecimal taxNum10 = new BigDecimal("0");
        BigDecimal taxNum20 = new BigDecimal("0");
        BigDecimal taxNum50 = new BigDecimal("0");
        BigDecimal taxNum100 = new BigDecimal("0");
        BigDecimal taxNum500 = new BigDecimal("0");
        BigDecimal taxNum1000 = new BigDecimal("0");
        BigDecimal taxNum3000 = new BigDecimal("0");

        BigDecimal constant = BigDecimal.valueOf(1.05);

        if (ObjectUtils.equals("H", tpAxleHoleType)) {
            // 料件成本
            materialsPartsCost = (ch.add(ci).add(cw).add(cv).add(da)).multiply(constant);
            // 加工成本
            processCost = (cl.add(cn).add(ct).add(cz)).multiply(constant);
        } else if (ObjectUtils.equals("P", tpAxleHoleType)) {
            // 料件成本
            materialsPartsCost = (ch.add(ci).add(cw).add(cv).add(da).add(cx)).multiply(constant);
            // 加工成本
            processCost = (cl.add(cn).add(ct).add(cz).add(cp).add(cy)).multiply(constant);
        } else if (ObjectUtils.equals("N", tpAxleHoleType) ||
                ObjectUtils.equals("C", tpAxleHoleType)) {
            // 料件成本
            materialsPartsCost = (ch.add(ci).add(cw).add(cv).add(da).add(cx)).multiply(constant);
            // 加工成本
            processCost = (cl.add(cn).add(ct).add(cz).add(cp).add(cy).add(cr)).multiply(constant);
        } else if (
                ObjectUtils.equals("V", tpAxleHoleType) ||
                        ObjectUtils.equals("F", tpAxleHoleType) ||
                        ObjectUtils.equals("W", tpAxleHoleType)
        ) {
            // 料件成本
            materialsPartsCost = (ch.add(ci).add(cw).add(cv).add(da)).multiply(constant);
            // 加工成本
            processCost = (cl.add(cn).add(ct).add(cz)).multiply(constant);
        } else if (ObjectUtils.equals("Y", tpAxleHoleType)) {
            // 料件成本
            materialsPartsCost = (ch.add(ci).add(cw).add(cv).add(da)).multiply(constant);
            // 加工成本
            processCost = (cl.add(cn).add(ct).add(cz)).multiply(constant);
        } else if (ObjectUtils.equals("D", tpAxleHoleType)) {
            // 料件成本
            materialsPartsCost = (ch.add(ci).add(cw).add(cv).add(da)).multiply(constant);
            // 加工成本
            processCost = (cl.add(cn).add(ct).add(cz).add(dc.multiply(BigDecimal.valueOf(5)))).multiply(constant);
        }

        // 零售价
        retailPrice = materialsPartsCost.divide(BigDecimal.valueOf(0.9), 10, RoundingMode.HALF_UP).add(processCost.multiply(BigDecimal.valueOf(1.7))).setScale(2, RoundingMode.HALF_UP);
        // 含税零售价
        taxRetailPrice = retailPrice.multiply(BigDecimal.valueOf(1.13));

        // 料件成本
        materialsPartsCost = materialsPartsCost.setScale(2, RoundingMode.HALF_UP);
        // 加工成本
        processCost = processCost.setScale(2, RoundingMode.HALF_UP);
        // 合计成本
        assessCost = materialsPartsCost.add(processCost).setScale(2, RoundingMode.HALF_UP);
        // 改孔费用
        dc = dc.setScale(2, RoundingMode.HALF_UP);

        BigDecimal ZeroPointNine = BigDecimal.valueOf(0.9);
        BigDecimal onePointSixOne = BigDecimal.valueOf(1.61);
        BigDecimal onePointOne = BigDecimal.valueOf(1.1);
        BigDecimal TwoThousand = BigDecimal.valueOf(2000);
        BigDecimal onePointZeroThree = BigDecimal.valueOf(1.03);

        // 1件
        num1 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(1).multiply(onePointOne).divide(BigDecimal.valueOf(1).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(1).add(onePointZeroThree)).divide(BigDecimal.valueOf(1), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(1), 6 ,RoundingMode.HALF_UP));
        taxNum1 = num1.multiply(BigDecimal.valueOf(1.13));
        // 2件
        num2 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(2).multiply(onePointOne).divide(BigDecimal.valueOf(2).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(2).add(onePointZeroThree)).divide(BigDecimal.valueOf(2), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(2), 6 ,RoundingMode.HALF_UP));
        taxNum2 = num2.multiply(BigDecimal.valueOf(1.13));
        // 3件
        num3 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(3).multiply(onePointOne).divide(BigDecimal.valueOf(3).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(3).add(onePointZeroThree)).divide(BigDecimal.valueOf(3), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(3), 6 ,RoundingMode.HALF_UP));
        taxNum3 = num3.multiply(BigDecimal.valueOf(1.13));
        // 4件
        num4 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(4).multiply(onePointOne).divide(BigDecimal.valueOf(4).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(4).add(onePointZeroThree)).divide(BigDecimal.valueOf(4), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(4), 6 ,RoundingMode.HALF_UP));
        taxNum4 = num4.multiply(BigDecimal.valueOf(1.13));
        // 5件
        num5 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(5).multiply(onePointOne).divide(BigDecimal.valueOf(5).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(5).add(onePointZeroThree)).divide(BigDecimal.valueOf(5), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(5), 6 ,RoundingMode.HALF_UP));
        taxNum5 = num5.multiply(BigDecimal.valueOf(1.13));

        // 10件
        num10 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(10).multiply(onePointOne).divide(BigDecimal.valueOf(10).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(10).add(onePointZeroThree)).divide(BigDecimal.valueOf(10), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(10), 6 ,RoundingMode.HALF_UP));
        taxNum10 = num10.multiply(BigDecimal.valueOf(1.13));
        // 20件
        num20 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(20).multiply(onePointOne).divide(BigDecimal.valueOf(20).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(20).add(onePointZeroThree)).divide(BigDecimal.valueOf(20), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(20), 6 ,RoundingMode.HALF_UP));
        taxNum20 = num20.multiply(BigDecimal.valueOf(1.13));
        // 50件
        num50 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(50).multiply(onePointOne).divide(BigDecimal.valueOf(50).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(50).add(onePointZeroThree)).divide(BigDecimal.valueOf(50), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(50), 6 ,RoundingMode.HALF_UP));
        taxNum50 = num50.multiply(BigDecimal.valueOf(1.13));
        // 100件
        num100 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(100).multiply(onePointOne).divide(BigDecimal.valueOf(100).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(100).add(onePointZeroThree)).divide(BigDecimal.valueOf(100), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(100), 6 ,RoundingMode.HALF_UP));
        taxNum100 = num100.multiply(BigDecimal.valueOf(1.13));
        // 500件
        num500 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(500).multiply(onePointOne).divide(BigDecimal.valueOf(500).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(500).add(onePointZeroThree)).divide(BigDecimal.valueOf(500), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(500), 6 ,RoundingMode.HALF_UP));
        taxNum500 = num500.multiply(BigDecimal.valueOf(1.13));
        // 1000件
        num1000 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(1000).multiply(onePointOne).divide(BigDecimal.valueOf(1000).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(1000).add(onePointZeroThree)).divide(BigDecimal.valueOf(1000), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(1000), 6 ,RoundingMode.HALF_UP));
        taxNum1000 = num1000.multiply(BigDecimal.valueOf(1.13));
        // 3000件
        num3000 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(3000).multiply(onePointOne).divide(BigDecimal.valueOf(3000).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(3000).add(onePointZeroThree)).divide(BigDecimal.valueOf(3000), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(3000), 6 ,RoundingMode.HALF_UP));
        taxNum3000 = num3000.multiply(BigDecimal.valueOf(1.13));


        costMap.put("materialsPartsCost", materialsPartsCost);
        costMap.put("processCost", processCost);
        costMap.put("assessCost", assessCost);

        costMap.put("retailPrice", retailPrice);
        costMap.put("taxRetailPrice", taxRetailPrice);

        costMap.put("num1", num1);
        costMap.put("num2", num2);
        costMap.put("num3", num3);
        costMap.put("num4", num4);
        costMap.put("num5", num5);
        costMap.put("num10", num10);
        costMap.put("num20", num20);
        costMap.put("num50", num50);
        costMap.put("num100", num100);
        costMap.put("num500", num500);
        costMap.put("num1000", num1000);
        costMap.put("num3000", num3000);

        costMap.put("taxNum1", taxNum1);
        costMap.put("taxNum2", taxNum2);
        costMap.put("taxNum3", taxNum3);
        costMap.put("taxNum4", taxNum4);
        costMap.put("taxNum5", taxNum5);
        costMap.put("taxNum10", taxNum10);
        costMap.put("taxNum20", taxNum20);
        costMap.put("taxNum50", taxNum50);
        costMap.put("taxNum100", taxNum100);
        costMap.put("taxNum500", taxNum500);
        costMap.put("taxNum1000", taxNum1000);
        costMap.put("taxNum3000", taxNum3000);
        return costMap;
    }

    /**
     * 往ERP系统导入商品数据
     */
    @Override
    public String commodityImportErp(String filePath, String fileName, Boolean containBK, HttpServletResponse response) throws Exception {

        List<ImportErp> importErpList = excelService.excelObjectList(ImportErp.class, filePath, fileName, false);

        ImportErp importErp = importErpList.get(0);

        String tpMaterial = importErp.getTpMaterial();
        String tpToothBandwidth = importErp.getTpToothBandwidth();
        String tpShape = importErp.getTpShape();
        String threeLevel = importErp.getThreeLevel();

        String[] splitMaterial = tpMaterial.split("-");
        String[] splitToothBandwidth = tpToothBandwidth.split("-");
        String[] splitShape = tpShape.split("-");
        String[] splitThreeLevel = threeLevel.split("-");

        List<ResultErp> resultErpList = new ArrayList<>();

        // 材质
        for (int i = 0; i < splitMaterial.length; i++) {
            // 齿形带宽
            for (int ii = 0; ii < splitToothBandwidth.length; ii++) {
                // 齿数
                for (int iii = 0; iii < importErpList.size(); iii++) {
                    // 形状
                    for (int iiii = 0; iiii < splitShape.length; iiii++) {
                        // 轴孔类型
                        for (int iiiii = 0; iiiii < splitThreeLevel.length; iiiii++) {

                            // 形状是否含有B、K
                            String shape = splitShape[iiii];
                            if ("B".equals(splitShape[iiii])) {
                                if (containBK) {
                                    if (ObjectUtils.isNotEmpty(importErpList.get(iii).getTpE()) && ObjectUtils.isNotEmpty(importErpList.get(iii).getTpD())
                                            && new BigDecimal(importErpList.get(iii).getTpE()).compareTo(new BigDecimal(importErpList.get(iii).getTpD())) > 0) {
                                        shape = "B";
                                    } else {
                                        shape = "K";
                                    }
                                }
                                if (ObjectUtils.isNotEmpty(importErpList.get(iii).getTpDe())) {
                                    shape = "D";
                                }
                            }

                            ResultErp resultErp = new ResultErp();
                            resultErp.setOneLevel(importErp.getOneLevel());
                            resultErp.setTwoLevel(importErp.getTwoLevel());

                            StringBuilder sb = new StringBuilder();
                            sb.append(importErp.getTpType()).append("-").append(splitShape[iiii]).append("-").append(splitThreeLevel[iiiii]);
                            resultErp.setThreeLevel(sb.toString());

                            sb.setLength(0);

                            sb.append(importErp.getTpType()).append(splitMaterial[i]).append("-").append(splitToothBandwidth[ii]).append("-")
                                    .append(importErpList.get(iii).getTpTeethNum()).append("-").append(shape).append("-")
                                    .append(splitThreeLevel[iiiii]).append("-").append("d").append(importErpList.get(iii).getMind());

                            resultErp.setCommodityCode(sb.toString());
                            resultErp.setCommodityName("同步轮");
                            resultErp.setType(resultErp.getCommodityCode());
                            resultErp.setUnit(importErp.getUnit());
                            resultErp.setCostCalculationMethod(importErp.getCostCalculationMethod());

                            // 切料
                            resultErp.setCutting("1");
                            // 车A面
                            resultErp.setVehicleA("2");
                            // 车B面
                            resultErp.setVehicleB("3");


                            if ("H".equals(splitThreeLevel[iiiii])) {
                                // 滚齿
                                resultErp.setHobbing("4");
                                // 压挡圈
                                resultErp.setPressureRetainingRing("5");
                            } else if ("P".equals(splitThreeLevel[iiiii])) {
                                // 滚齿
                                resultErp.setHobbing("4");
                                // 钻攻
                                resultErp.setDrillingAttack("5");
                                // 压挡圈
                                resultErp.setPressureRetainingRing("6");
                            } else if ("N".equals(splitThreeLevel[iiiii])) {
                                // 滚齿
                                resultErp.setHobbing("4");
                                // 钻攻
                                resultErp.setDrillingAttack("5");
                                // 拉键槽
                                resultErp.setPullingKeyGroove("6");
                                // 压挡圈
                                resultErp.setPressureRetainingRing("7");
                            }

                            // 表面处理
                            int number = Integer.parseInt(resultErp.getPressureRetainingRing());
                            number++;
                            String surface = Integer.toString(number);
                            if ("A".equals(splitMaterial[i])) {
                                resultErp.setSurfaceNot(surface);
                            } else if ("H".equals(splitMaterial[i])) {
                                resultErp.setSurfaceAnode(surface);
                                resultErp.setSurfaceTreatmentMethod("本色阳极氧化");
                            } else if ("HK".equals(splitMaterial[i])) {
                                resultErp.setSurfaceAnodeColor(surface);
                                resultErp.setSurfaceTreatmentMethod("黑色阳极氧化");
                            } else if ("K".equals(splitMaterial[i])) {
                                resultErp.setSurfaceOther(surface);
                                resultErp.setSurfaceTreatmentMethod("硬质阳极氧化");
                            } else if ("R".equals(splitMaterial[i])) {
                                resultErp.setSurfaceNickeling(surface);
                                resultErp.setSurfaceTreatmentMethod("镀镍");
                            } else if ("F".equals(splitMaterial[i])) {
                                resultErp.setSurfaceNot(surface);
                            } else if ("C".equals(splitMaterial[i])) {
                                resultErp.setSurfaceTurnBlack(surface);
                                resultErp.setSurfaceTreatmentMethod("发黑");
                            } else if ("D".equals(splitMaterial[i])) {
                                resultErp.setSurfaceNickeling(surface);
                                resultErp.setSurfaceTreatmentMethod("镀镍");
                            } else if ("S".equals(splitMaterial[i])) {
                                resultErp.setSurfaceNot(surface);
                            }

                            // 加工完成
                            resultErp.setProcessingCompleted(Integer.toString(Integer.parseInt(surface) + 1));

                            // 规格 A:7_W:11_d:4_车:12.81_E:10
                            LambdaQueryWrapper<HlTimingPulley> hlTimingPulleyWrapper = new LambdaQueryWrapper<>();
                            hlTimingPulleyWrapper.eq(HlTimingPulley::getTpType, importErp.getTpType())
                                                    .eq(HlTimingPulley::getTpMaterial, splitMaterial[i])
                                                    .eq(HlTimingPulley::getTpToothBandwidth, splitToothBandwidth[ii])
                                                    .eq(HlTimingPulley::getTpTeethNum, importErpList.get(iii).getTpTeethNum())
                                                    .eq(HlTimingPulley::getTpShape, shape);
                            HlTimingPulley hlTimingPulley = hlTimingPulleyMapper.selectOne(hlTimingPulleyWrapper);
                            // 查询 带宽表 hl_bandwidth
                            // 以此获得 bandwidth_a 、 bandwidth_w 、 bandwidth_l 信息
                            HlBandwidth hlBandwidth = new HlBandwidth();
                            hlBandwidth.setBandwidth(splitToothBandwidth[ii]);
                            List<HlBandwidth> hlBandwidths = hlBandwidthService.selectHlBandwidthList(hlBandwidth);
                            hlBandwidth = resultHlBandwidth(new BigDecimal(importErpList.get(iii).getTpTeethNum()), hlBandwidths);
                            if (ObjectUtils.isNotEmpty(hlTimingPulley) && ObjectUtils.isNotEmpty(hlBandwidth)) {
                                BigDecimal che = new BigDecimal(hlTimingPulley.getTpOd()).add(BigDecimal.valueOf(0.2));
                                if (che.compareTo(che.setScale(0, RoundingMode.HALF_UP)) == 0) {
                                    // 如果是整数，使用stripTrailingZeros()
                                    che = che.setScale(0, RoundingMode.HALF_UP);
                                } else {
                                    // 如果不是整数，设置指定的小数位数
                                    che = che.stripTrailingZeros();
                                }
                                sb = new StringBuilder();
                                sb.append("A：").append(hlBandwidth.getBandwidthA().stripTrailingZeros()).append("_W：").append(hlBandwidth.getBandwidthW().stripTrailingZeros())
                                        .append("_d：").append(importErpList.get(iii).getMind()).append("_车：").append(che)
                                        .append("_E：").append(hlTimingPulley.getTpE());
                                resultErp.setSpecs(sb.toString());
                            }

                            // AjaxResult ajaxResult = tpCostPrice(resultErp.getCommodityCode(), null, null, false, false);
                            // ResultTimingPulleyPrice resultTimingPulleyPrice = (ResultTimingPulleyPrice) ajaxResult.get("data");
                            // 单价
                            // resultErp.setRetailPrice(resultTimingPulleyPrice.getNum1());


                            resultErp.setProductionType("加工");

                            resultErpList.add(resultErp);
                        }
                    }
                }
            }
        }
        log.info("往ERP系统导入商品数据的大小 ==> {}", resultErpList.size());
        String excelName = importErp.getTpType() + "_" + splitToothBandwidth[0].substring(0, splitToothBandwidth[0].length() - 3);
        return excelService.wired(resultErpList, ResultErp.class, excelName, response);
    }


    /**
     * ERP系统BOM表批量导入功能生成材料Excel表
     * 材料表
     */
    @Override
    public Map<String, Object> bomMaterialImportErp(String filePath, String fileName, HttpServletResponse response) throws Exception {
        // 商品数据集合
        List<ResultErp> resultErpList = excelService.excelObjectList(ResultErp.class, filePath, fileName, false);

        // 材料
        String material = "材料";
        String materialPath = "D:\\华链-胡健\\2024-01-16ERP商品录入功能\\加工后的Excel表\\";
        String materialName = material + ".xlsx";
        // 材料对应的 对应工序
        String materialCorrespondingProcess = "切料";
        List<BomMaterial> bomMaterialList = excelService.excelObjectList(BomMaterial.class, materialPath, materialName, false);

        List<ResultBom> resultAluminiumMaterialBomList = new ArrayList<>();
        List<ResultBom> resultIronMaterialBomList = new ArrayList<>();
        List<ResultBom> resultBomList = new ArrayList<>();
        Set<String> notCommunityInformationList = new HashSet<>();
        Set<String> notAluminiumMaterialBomList = new HashSet<>();
        Set<String> notIronMaterialBomList = new HashSet<>();

        // 整个 bomMaterialList 集合拆分成 铝 和 铁
        List<BomMaterial> aluminiumBomMaterialList = bomMaterialList.stream()
                .filter(bomMaterial -> bomMaterial.getType().contains("铝"))
                .collect(Collectors.toList());
        List<BomMaterial> ironBomMaterialList = bomMaterialList.stream()
                .filter(bomMaterial -> bomMaterial.getType().contains("铁"))
                .collect(Collectors.toList());

        // 商品信息
        for (ResultErp resultErp : resultErpList) {
            ResultBom resultBom = new ResultBom();

            String commodityCode = resultErp.getCommodityCode();

            Map<String, String> communityInformationMap = communityInformationMap(commodityCode);
            if (ObjectUtils.isEmpty(communityInformationMap)) {
                // 未查到具体商品信息的商品数据编码集合大小
                notCommunityInformationList.add(commodityCode);
                continue;
            }

            // 材质
            String materialMark = communityInformationMap.get("materialMark");

            // 同步轮材料尺寸
            String materialSize = communityInformationMap.get("materialSize");
            String[] materialSizeSplit = materialSize.split("\\*");

            // 用Bom表的规格做比较
            if ("A".equals(materialMark) ||
                    "H".equals(materialMark) ||
                    "HK".equals(materialMark) ||
                    "K".equals(materialMark) ||
                    "R".equals(materialMark)
            ) {
                // 商品对应Bom信息 --> 铝
                for (int i = 0; i < aluminiumBomMaterialList.size(); i++) {
                    BomMaterial bomMaterial = aluminiumBomMaterialList.get(i);

                    String specs = bomMaterial.getSpecs();
                    String[] split = specs.split("\\*");
                    // 材料外径
                    String D = split[0].substring(1);

                    if (materialSizeSplit[0].equals(D)) {
                        // 加工件编码
                        resultBom.setWorkpieceCode(resultErp.getCommodityCode());
                        // 下级物料编码
                        resultBom.setSubordinateMaterialsCode(bomMaterial.getCommodityCode());
                        // 下级物料名称
                        resultBom.setSubordinateMaterialsName(bomMaterial.getCommodityName());
                        // 下级物料规格
                        resultBom.setSubordinateMaterialsSpecs(bomMaterial.getSpecs().split("\\*")[0] + "*" + materialSizeSplit[1]);
                        // 下级物料型号
                        resultBom.setSubordinateMaterialsType(bomMaterial.getType());
                        // 底数
                        resultBom.setBaseNumber("2500");
                        // 用量
                        resultBom.setDosage(materialSizeSplit[1]);
                        // 单位
                        resultBom.setUnit(bomMaterial.getUnit());
                        // 损耗率
                        resultBom.setLossRate("2");
                        // 对应工序
                        resultBom.setCorrespondingProcess(materialCorrespondingProcess);
                        resultAluminiumMaterialBomList.add(resultBom);
                        resultBomList.add(resultBom);
                        break;
                    }

                    // 如果此商品没找对应的Bom信息，可以保存一下数据，手动添加
                    if (i == aluminiumBomMaterialList.size() - 1) {
                        notAluminiumMaterialBomList.add(commodityCode);
                    }
                }
            }  else if ("F".equals(materialMark) ||
                    "C".equals(materialMark) ||
                    "D".equals(materialMark) ||
                    "S".equals(materialMark)
            ) {
                // 商品对应Bom信息 --> 铁
                for (int i = 0; i < ironBomMaterialList.size(); i++) {
                    BomMaterial bomMaterial = ironBomMaterialList.get(i);

                    String specs = bomMaterial.getSpecs();
                    String[] split = specs.split("\\*");
                    // 材料外径
                    String D = split[0].substring(1);

                    if (materialSizeSplit[0].equals(D)) {
                        // 加工件编码
                        resultBom.setWorkpieceCode(resultErp.getCommodityCode());
                        // 下级物料编码
                        resultBom.setSubordinateMaterialsCode(bomMaterial.getCommodityCode());
                        // 下级物料名称
                        resultBom.setSubordinateMaterialsName(bomMaterial.getCommodityName());
                        // 下级物料规格
                        /*
                            if (new BigDecimal(materialSizeSplit[0]).compareTo(BigDecimal.valueOf(45)) <= 0) {
                                   resultBom.setSubordinateMaterialsSpecs(bomMaterial.getSpecs().split("\\*")[0] + "*" + "830");
                               } else {
                                   resultBom.setSubordinateMaterialsSpecs(bomMaterial.getSpecs().split("\\*")[0] + "*" + materialSizeSplit[1]);
                            } 
                        */
                        resultBom.setSubordinateMaterialsSpecs(bomMaterial.getSpecs().split("\\*")[0] + "*" + materialSizeSplit[1]);
                        // 下级物料型号
                        resultBom.setSubordinateMaterialsType(bomMaterial.getType());
                        // 底数
                        resultBom.setBaseNumber("2500");
                        // 用量
                        resultBom.setDosage(materialSizeSplit[1]);
                        // 单位
                        resultBom.setUnit(bomMaterial.getUnit());
                        // 损耗率
                        resultBom.setLossRate("2");
                        // 对应工序
                        resultBom.setCorrespondingProcess(materialCorrespondingProcess);
                        resultIronMaterialBomList.add(resultBom);
                        resultBomList.add(resultBom);
                        break;
                    }

                    // 如果此商品没找对应的Bom信息，可以保存一下数据，手动添加
                    if (i == aluminiumBomMaterialList.size() - 1) {
                        notIronMaterialBomList.add(commodityCode);
                    }
                }
            }
        }

        log.info("商品数据集合大小 ==> {}", resultErpList.size());
        log.info("未查到具体商品信息的商品数据编码集合大小 ==> {}", notCommunityInformationList.size());

        log.info(fileName + "对应BOM信息残缺的商品数据编码集合大小(铝)===" + material + " ==> {}", notAluminiumMaterialBomList.size());
        log.info(fileName + "对应BOM信息残缺的商品数据编码集合大小(铁)===" + material + " ==> {}", notIronMaterialBomList.size());
        log.info(fileName + "对应BOM数据集合大小(铝)===" + material + " ==> {}", resultAluminiumMaterialBomList.size());
        log.info(fileName + "对应BOM数据集合大小(铁)===" + material + " ==> {}", resultIronMaterialBomList.size());

        Set<String> mergeList = new HashSet<>();
        mergeList.addAll(notCommunityInformationList);
        mergeList.addAll(notAluminiumMaterialBomList);
        mergeList.addAll(notIronMaterialBomList);
        log.info("未处理的商品数据集合大小===" + material + " ==> {}", mergeList.size());

        log.info("未查到具体商品信息的商品数据编码集合===" + material + " ==> {}", JSON.toJSONString(notCommunityInformationList));
        log.info(fileName + "对应BOM信息残缺的商品数据编码集合(铝)===" + material + " ==> {}", notAluminiumMaterialBomList);
        log.info(fileName + "对应BOM信息残缺的商品数据编码集合(铁)===" + material + " ==> {}", notIronMaterialBomList);

        Set<String> resultNotBomMaterialList = new HashSet<>(notCommunityInformationList);
        resultNotBomMaterialList.addAll(notAluminiumMaterialBomList);
        resultNotBomMaterialList.addAll(notIronMaterialBomList);
        Map<String, Object> map = new HashMap<>();
        map.put("resultBomMaterialList", resultBomList);
        map.put("resultNotBomMaterialList", resultNotBomMaterialList);
        return map;
        // return excelService.wired(resultBomList, ResultBom.class, fileName.split("\\.")[0] + "对应BOM数据===" + material, response);
    }

    /**
     * ERP系统BOM表批量导入功能生成挡圈Excel表
     * 挡圈表
     */
    @Override
    public Map<String, Object> bomRingImportErp(String filePath, String fileName, HttpServletResponse response) throws Exception {
        // 商品数据集合
        List<ResultErp> resultErpList = excelService.excelObjectList(ResultErp.class, filePath, fileName, false);

        // 挡圈
        String ring = "挡圈";
        String ringPath = "D:\\华链-胡健\\2024-01-16ERP商品录入功能\\加工后的Excel表\\";
        String ringName = "挡圈.xlsx";
        // 挡圈对应的 对应工序
        String ringCorrespondingProcess = "压挡圈";
        List<BomMaterial> bomRingList = excelService.excelObjectList(BomMaterial.class, ringPath, ringName, false);

        List<ResultBom> resultAluminiumMaterialBomList = new ArrayList<>();
        List<ResultBom> resultIronMaterialBomList = new ArrayList<>();
        List<ResultBom> resultBomList = new ArrayList<>();
        Set<String> notCommunityInformationList = new HashSet<>();
        Set<String> notAluminiumMaterialBomList = new HashSet<>();
        Set<String> notIronMaterialBomList = new HashSet<>();


        // 整个 bomMaterialList 集合拆分成 铝 和 铁
        List<BomMaterial> aluminiumBomMaterialList = bomRingList.stream()
                .filter(bomMaterial -> bomMaterial.getType().contains("铝"))
                .collect(Collectors.toList());
        List<BomMaterial> ironBomMaterialList = bomRingList.stream()
                .filter(bomMaterial -> bomMaterial.getType().contains("铁"))
                .collect(Collectors.toList());

        Set<String> commoditySpecs = new HashSet<>();

        // 商品信息
        for (ResultErp resultErp : resultErpList) {
            ResultBom resultBom = new ResultBom();

            String commodityCode = resultErp.getCommodityCode();

            Map<String, String> communityInformationMap = communityInformationMap(commodityCode);
            if (ObjectUtils.isEmpty(communityInformationMap)) {
                // 未查到具体商品信息的商品数据编码集合大小
                notCommunityInformationList.add(commodityCode);
                continue;
            }

            // 材质
            String materialMark = communityInformationMap.get("materialMark");

            String tpF = communityInformationMap.get("tpF");
            String tpE = communityInformationMap.get("tpE");
            String tpT = communityInformationMap.get("tpT");

            // TPH-H100-17-A-N-d22-FC72
            // IGH-T5150-20-W-698-FC32
            String[] split = commodityCode.split("-");
            log.info("commodityCode ==> {}", commodityCode);
            if (commodityCode.contains("FC")) {
                String fc = "";
                for (String s : split) {
                    if (s.contains("FC")) {
                        fc = s;
                        break;
                    }
                }
                BigDecimal tpFBigDecimal = new BigDecimal(fc.substring(2));
                // 向下取整
                tpFBigDecimal = tpFBigDecimal.setScale(0, RoundingMode.DOWN);

                HlFlange hlFlange = new HlFlange();
                List<HlFlange> hlFlangeList = hlFlangeService.selectHlFlangeList(hlFlange);

                BigDecimal finalTpFBigDecimal = tpFBigDecimal;
                List<HlFlange> extractHlFlangeList = hlFlangeList.stream()
                        .filter(flange -> flange.getFlangeOutsideDiameter().equals(finalTpFBigDecimal.toString()))
                        .collect(Collectors.toList());
                if (ObjectUtils.isEmpty(extractHlFlangeList)) {
                    notAluminiumMaterialBomList.add(commodityCode);
                    break;
                }
                if (extractHlFlangeList.size() == 1) {
                    hlFlange = extractHlFlangeList.get(0);
                } else {
                    // 排序，内径大的放前面
                    extractHlFlangeList.sort((s1, s2) -> Double.compare(Double.parseDouble(s2.getFlangeInsideDiametere()), Double.parseDouble(s1.getFlangeInsideDiametere())));
                    hlFlange = extractHlFlangeList.get(0);
                }
                tpF = tpFBigDecimal.toString();
                tpE = hlFlange.getFlangeInsideDiametere();
            }

            if ("1.0".equals(tpT)) {
                tpT = "1.2";
            }

            String communitySpecs = "φ" + tpF + "*" + "φ" + tpE +  "*" + tpT;

            // 同步轮是 K 形状的，挡圈多加一个厚的 TPH-S3M100-18-K-P-d8

            // 用Bom表的规格做比较
            if (
                    "H".equals(materialMark) ||
                    "HK".equals(materialMark) ||
                    "K".equals(materialMark) ||
                    "R".equals(materialMark)
            ) {
                // 商品对应Bom信息 --> 铝
                for (int i = 0; i < aluminiumBomMaterialList.size(); i++) {
                    BomMaterial bomMaterial = aluminiumBomMaterialList.get(i);

                    String specs = bomMaterial.getSpecs();

                    if (communitySpecs.equals(specs)) {
                        // 加工件编码
                        resultBom.setWorkpieceCode(resultErp.getCommodityCode());
                        // 下级物料编码
                        resultBom.setSubordinateMaterialsCode(bomMaterial.getCommodityCode());
                        // 下级物料名称
                        resultBom.setSubordinateMaterialsName(bomMaterial.getCommodityName());
                        // 下级物料规格
                        resultBom.setSubordinateMaterialsSpecs(bomMaterial.getSpecs());
                        // 下级物料型号
                        resultBom.setSubordinateMaterialsType(bomMaterial.getType());
                        // 底数
                        resultBom.setBaseNumber("1");
                        if ("K".equals(split[3]) || "K".equals(split[4])) {
                            String communitySpecsK = "φ" + tpF + "*" + "φ" + tpE +  "*10";
                            for (int iii = 0; iii < aluminiumBomMaterialList.size(); iii++) {
                                BomMaterial bomMaterialK = aluminiumBomMaterialList.get(iii);
                                String specsK = bomMaterialK.getSpecs();
                                if (communitySpecsK.equals(specsK)) {
                                    ResultBom resultBomK = new ResultBom();
                                    // 加工件编码
                                    resultBomK.setWorkpieceCode(resultErp.getCommodityCode());
                                    // 下级物料编码
                                    resultBomK.setSubordinateMaterialsCode(bomMaterialK.getCommodityCode());
                                    // 下级物料名称
                                    resultBomK.setSubordinateMaterialsName(bomMaterialK.getCommodityName());
                                    // 下级物料规格
                                    resultBomK.setSubordinateMaterialsSpecs(bomMaterialK.getSpecs());
                                    // 下级物料型号
                                    resultBomK.setSubordinateMaterialsType(bomMaterialK.getType());
                                    // 底数
                                    resultBomK.setBaseNumber("1");
                                    // 用量
                                    resultBomK.setDosage("1");
                                    // 单位
                                    resultBomK.setUnit(bomMaterialK.getUnit());
                                    // 损耗率
                                    resultBomK.setLossRate("0");
                                    // 对应工序
                                    resultBomK.setCorrespondingProcess(ringCorrespondingProcess);
                                    resultAluminiumMaterialBomList.add(resultBomK);
                                    resultBomList.add(resultBomK);
                                    break;
                                }
                                if (iii == aluminiumBomMaterialList.size() - 1) {
                                    notAluminiumMaterialBomList.add(commodityCode);
                                    commoditySpecs.add(communitySpecs);
                                }
                            }
                            // 用量
                            resultBom.setDosage("1");
                        } else {
                            // 用量
                            resultBom.setDosage("2");
                        }
                        // 单位
                        resultBom.setUnit(bomMaterial.getUnit());
                        // 损耗率
                        resultBom.setLossRate("0");
                        // 对应工序
                        resultBom.setCorrespondingProcess(ringCorrespondingProcess);
                        resultAluminiumMaterialBomList.add(resultBom);
                        resultBomList.add(resultBom);
                        break;
                    }

                    // 如果此商品没找对应的Bom信息，可以保存一下数据，手动添加
                    if (i == aluminiumBomMaterialList.size() - 1) {
                        HlFlange hlFlange = new HlFlange();
                        hlFlange.setFlangeOutsideDiameter(tpF);
                        List<HlFlange> hlFlangeList = hlFlangeService.selectHlFlangeList(hlFlange);

                        if (ObjectUtils.isNotEmpty(hlFlangeList)) {
                            // 排序，内径大的放前面
                            hlFlangeList.sort((s1, s2) -> Double.compare(Double.parseDouble(s2.getFlangeInsideDiametere()), Double.parseDouble(s1.getFlangeInsideDiametere())));
                            hlFlange = hlFlangeList.get(0);

                            communitySpecs = "φ" + tpF + "*" + "φ" + hlFlange.getFlangeInsideDiametere() +  "*" + tpT;

                            for (int ii = 0; ii < aluminiumBomMaterialList.size(); ii++) {
                                bomMaterial = aluminiumBomMaterialList.get(ii);
                                specs = bomMaterial.getSpecs();
                                if (communitySpecs.equals(specs)) {
                                    // 加工件编码
                                    resultBom.setWorkpieceCode(resultErp.getCommodityCode());
                                    // 下级物料编码
                                    resultBom.setSubordinateMaterialsCode(bomMaterial.getCommodityCode());
                                    // 下级物料名称
                                    resultBom.setSubordinateMaterialsName(bomMaterial.getCommodityName());
                                    // 下级物料规格
                                    resultBom.setSubordinateMaterialsSpecs(bomMaterial.getSpecs());
                                    // 下级物料型号
                                    resultBom.setSubordinateMaterialsType(bomMaterial.getType());
                                    // 底数
                                    resultBom.setBaseNumber("1");
                                    if ("K".equals(split[3]) || "K".equals(split[4])) {
                                        String communitySpecsK = "φ" + tpF + "*" + "φ" + tpE +  "*10";
                                        for (int iii = 0; iii < aluminiumBomMaterialList.size(); iii++) {
                                            BomMaterial bomMaterialK = aluminiumBomMaterialList.get(iii);
                                            String specsK = bomMaterialK.getSpecs();
                                            if (communitySpecsK.equals(specsK)) {
                                                ResultBom resultBomK = new ResultBom();
                                                // 加工件编码
                                                resultBomK.setWorkpieceCode(resultErp.getCommodityCode());
                                                // 下级物料编码
                                                resultBomK.setSubordinateMaterialsCode(bomMaterialK.getCommodityCode());
                                                // 下级物料名称
                                                resultBomK.setSubordinateMaterialsName(bomMaterialK.getCommodityName());
                                                // 下级物料规格
                                                resultBomK.setSubordinateMaterialsSpecs(bomMaterialK.getSpecs());
                                                // 下级物料型号
                                                resultBomK.setSubordinateMaterialsType(bomMaterialK.getType());
                                                // 底数
                                                resultBomK.setBaseNumber("1");
                                                // 用量
                                                resultBomK.setDosage("1");
                                                // 单位
                                                resultBomK.setUnit(bomMaterialK.getUnit());
                                                // 损耗率
                                                resultBomK.setLossRate("0");
                                                // 对应工序
                                                resultBomK.setCorrespondingProcess(ringCorrespondingProcess);
                                                resultAluminiumMaterialBomList.add(resultBomK);
                                                resultBomList.add(resultBomK);
                                                break;
                                            }
                                            if (iii == aluminiumBomMaterialList.size() - 1) {
                                                notAluminiumMaterialBomList.add(commodityCode);
                                                commoditySpecs.add(communitySpecs);
                                            }
                                        }
                                        // 用量
                                        resultBom.setDosage("1");
                                    } else {
                                        // 用量
                                        resultBom.setDosage("2");
                                    }
                                    // 单位
                                    resultBom.setUnit(bomMaterial.getUnit());
                                    // 损耗率
                                    resultBom.setLossRate("0");
                                    // 对应工序
                                    resultBom.setCorrespondingProcess(ringCorrespondingProcess);
                                    resultAluminiumMaterialBomList.add(resultBom);
                                    resultBomList.add(resultBom);
                                    break;
                                }
                                if (ii == aluminiumBomMaterialList.size() - 1) {
                                    notAluminiumMaterialBomList.add(commodityCode);
                                    commoditySpecs.add(communitySpecs);
                                }
                            }
                        } else {
                            notAluminiumMaterialBomList.add(commodityCode);
                            commoditySpecs.add(communitySpecs);
                        }
                    }
                }
            }  else if (
                    "A".equals(materialMark) ||
                    "F".equals(materialMark) ||
                    "C".equals(materialMark) ||
                    "D".equals(materialMark) ||
                    "S".equals(materialMark)
            ) {
                // 商品对应Bom信息 --> 铁
                for (int i = 0; i < ironBomMaterialList.size(); i++) {
                    BomMaterial bomMaterial = ironBomMaterialList.get(i);

                    String specs = bomMaterial.getSpecs();

                    if (communitySpecs.equals(specs)) {
                        // 加工件编码
                        resultBom.setWorkpieceCode(resultErp.getCommodityCode());
                        // 下级物料编码
                        resultBom.setSubordinateMaterialsCode(bomMaterial.getCommodityCode());
                        // 下级物料名称
                        resultBom.setSubordinateMaterialsName(bomMaterial.getCommodityName());
                        // 下级物料规格
                        resultBom.setSubordinateMaterialsSpecs(bomMaterial.getSpecs());
                        // 下级物料型号
                        resultBom.setSubordinateMaterialsType(bomMaterial.getType());
                        // 底数
                        resultBom.setBaseNumber("1");
                        if ("K".equals(split[3]) || "K".equals(split[4])) {
                            String communitySpecsK = "φ" + tpF + "*" + "φ" + tpE +  "*10";
                            for (int iii = 0; iii < ironBomMaterialList.size(); iii++) {
                                BomMaterial bomMaterialK = ironBomMaterialList.get(iii);
                                String specsK = bomMaterialK.getSpecs();
                                if (communitySpecsK.equals(specsK)) {
                                    ResultBom resultBomK = new ResultBom();
                                    // 加工件编码
                                    resultBomK.setWorkpieceCode(resultErp.getCommodityCode());
                                    // 下级物料编码
                                    resultBomK.setSubordinateMaterialsCode(bomMaterialK.getCommodityCode());
                                    // 下级物料名称
                                    resultBomK.setSubordinateMaterialsName(bomMaterialK.getCommodityName());
                                    // 下级物料规格
                                    resultBomK.setSubordinateMaterialsSpecs(bomMaterialK.getSpecs());
                                    // 下级物料型号
                                    resultBomK.setSubordinateMaterialsType(bomMaterialK.getType());
                                    // 底数
                                    resultBomK.setBaseNumber("1");
                                    // 用量
                                    resultBomK.setDosage("1");
                                    // 单位
                                    resultBomK.setUnit(bomMaterialK.getUnit());
                                    // 损耗率
                                    resultBomK.setLossRate("0");
                                    // 对应工序
                                    resultBomK.setCorrespondingProcess(ringCorrespondingProcess);
                                    resultAluminiumMaterialBomList.add(resultBomK);
                                    resultBomList.add(resultBomK);
                                    break;
                                }
                                if (iii == ironBomMaterialList.size() - 1) {
                                    notIronMaterialBomList.add(commodityCode);
                                    commoditySpecs.add(communitySpecs);
                                }
                            }
                            // 用量
                            resultBom.setDosage("1");
                        } else {
                            // 用量
                            resultBom.setDosage("2");
                        }
                        // 单位
                        resultBom.setUnit(bomMaterial.getUnit());
                        // 损耗率
                        resultBom.setLossRate("0");
                        // 对应工序
                        resultBom.setCorrespondingProcess(ringCorrespondingProcess);
                        resultIronMaterialBomList.add(resultBom);
                        resultBomList.add(resultBom);
                        break;
                    }

                    // 如果此商品没找对应的Bom信息，可以保存一下数据，手动添加
                    if (i == ironBomMaterialList.size() - 1) {
                        HlFlange hlFlange = new HlFlange();
                        hlFlange.setFlangeOutsideDiameter(tpF);
                        List<HlFlange> hlFlangeList = hlFlangeService.selectHlFlangeList(hlFlange);

                        if (ObjectUtils.isNotEmpty(hlFlangeList)) {
                            // 排序，内径大的放前面
                            hlFlangeList.sort((s1, s2) -> Double.compare(Double.parseDouble(s2.getFlangeInsideDiametere()), Double.parseDouble(s1.getFlangeInsideDiametere())));
                            hlFlange = hlFlangeList.get(0);

                            communitySpecs = "φ" + tpF + "*" + "φ" + hlFlange.getFlangeInsideDiametere() +  "*" + tpT;

                            for (int ii = 0; ii < ironBomMaterialList.size(); ii++) {
                                bomMaterial = ironBomMaterialList.get(ii);
                                specs = bomMaterial.getSpecs();
                                if (communitySpecs.equals(specs)) {
                                    // 加工件编码
                                    resultBom.setWorkpieceCode(resultErp.getCommodityCode());
                                    // 下级物料编码
                                    resultBom.setSubordinateMaterialsCode(bomMaterial.getCommodityCode());
                                    // 下级物料名称
                                    resultBom.setSubordinateMaterialsName(bomMaterial.getCommodityName());
                                    // 下级物料规格
                                    resultBom.setSubordinateMaterialsSpecs(bomMaterial.getSpecs());
                                    // 下级物料型号
                                    resultBom.setSubordinateMaterialsType(bomMaterial.getType());
                                    // 底数
                                    resultBom.setBaseNumber("1");
                                    if ("K".equals(split[3]) || "K".equals(split[4])) {
                                        String communitySpecsK = "φ" + tpF + "*" + "φ" + tpE +  "*10";
                                        for (int iii = 0; iii < ironBomMaterialList.size(); iii++) {
                                            BomMaterial bomMaterialK = ironBomMaterialList.get(iii);
                                            String specsK = bomMaterialK.getSpecs();
                                            if (communitySpecsK.equals(specsK)) {
                                                ResultBom resultBomK = new ResultBom();
                                                // 加工件编码
                                                resultBomK.setWorkpieceCode(resultErp.getCommodityCode());
                                                // 下级物料编码
                                                resultBomK.setSubordinateMaterialsCode(bomMaterialK.getCommodityCode());
                                                // 下级物料名称
                                                resultBomK.setSubordinateMaterialsName(bomMaterialK.getCommodityName());
                                                // 下级物料规格
                                                resultBomK.setSubordinateMaterialsSpecs(bomMaterialK.getSpecs());
                                                // 下级物料型号
                                                resultBomK.setSubordinateMaterialsType(bomMaterialK.getType());
                                                // 底数
                                                resultBomK.setBaseNumber("1");
                                                // 用量
                                                resultBomK.setDosage("1");
                                                // 单位
                                                resultBomK.setUnit(bomMaterialK.getUnit());
                                                // 损耗率
                                                resultBomK.setLossRate("0");
                                                // 对应工序
                                                resultBomK.setCorrespondingProcess(ringCorrespondingProcess);
                                                resultAluminiumMaterialBomList.add(resultBomK);
                                                resultBomList.add(resultBomK);
                                                break;
                                            }
                                            if (iii == ironBomMaterialList.size() - 1) {
                                                notIronMaterialBomList.add(commodityCode);
                                                commoditySpecs.add(communitySpecs);
                                            }
                                        }
                                        // 用量
                                        resultBom.setDosage("1");
                                    } else {
                                        // 用量
                                        resultBom.setDosage("2");
                                    }
                                    // 单位
                                    resultBom.setUnit(bomMaterial.getUnit());
                                    // 损耗率
                                    resultBom.setLossRate("0");
                                    // 对应工序
                                    resultBom.setCorrespondingProcess(ringCorrespondingProcess);
                                    resultIronMaterialBomList.add(resultBom);
                                    resultBomList.add(resultBom);
                                    break;
                                }
                                if (ii == ironBomMaterialList.size() - 1) {
                                    notIronMaterialBomList.add(commodityCode);
                                    commoditySpecs.add(communitySpecs);
                                }
                            }
                        } else {
                            notIronMaterialBomList.add(commodityCode);
                            commoditySpecs.add(communitySpecs);
                        }
                    }
                }
            }
        }



        log.info("商品数据集合大小 ==> {}", resultErpList.size());
        log.info("未查到具体商品信息的商品数据编码集合大小 ==> {}", notCommunityInformationList.size());

        log.info(fileName + "对应BOM信息残缺的商品数据编码集合大小(铝)===" + ring + " ==> {}", notAluminiumMaterialBomList.size());
        log.info(fileName + "对应BOM信息残缺的商品数据编码集合大小(铁)===" + ring + " ==> {}", notIronMaterialBomList.size());
        log.info(fileName + "对应BOM数据集合大小(铝)===" + ring + " ==> {}", resultAluminiumMaterialBomList.size());
        log.info(fileName + "对应BOM数据集合大小(铁)===" + ring + " ==> {}", resultIronMaterialBomList.size());

        Set<String> mergeList = new HashSet<>();
        mergeList.addAll(notCommunityInformationList);
        mergeList.addAll(notAluminiumMaterialBomList);
        mergeList.addAll(notIronMaterialBomList);
        log.info("未处理的商品数据集合大小===" + ring + " ==> {}", mergeList.size());

        log.info("未查到具体商品信息的商品数据编码集合===" + ring + " ==> {}", JSON.toJSONString(notCommunityInformationList));
        log.info(fileName + "对应BOM信息残缺的商品数据编码集合(铝)===" + ring + " ==> {}", notAluminiumMaterialBomList);
        log.info(fileName + "对应BOM信息残缺的商品数据编码集合(铁)===" + ring + " ==> {}", notIronMaterialBomList);

        log.info(fileName + "对应BOM信息残缺的挡圈规格 ==> {}", commoditySpecs);

        Set<String> resultNotBomRingList = new HashSet<>(notCommunityInformationList);
        resultNotBomRingList.addAll(notAluminiumMaterialBomList);
        resultNotBomRingList.addAll(notIronMaterialBomList);
        Map<String, Object> map = new HashMap<>();
        map.put("resultBomRingList", resultBomList);
        map.put("resultNotBomRingList", resultNotBomRingList);
        return map;
        // return excelService.wired(resultBomList, ResultBom.class, fileName.split("\\.")[0] + "对应BOM数据===" + ring, response);
    }

    /**
     * ERP系统BOM表批量导入功能生成轴承Excel表
     */
    public Map<String, Object> bomBearingImportErp(String filePath, String fileName, HttpServletResponse response) throws Exception {

        // 商品数据集合
        List<ResultErp> resultErpList = excelService.excelObjectList(ResultErp.class, filePath, fileName, false);

        String bearing = "轴承";
        String bearingPath = "D:\\华链-胡健\\2024-01-16ERP商品录入功能\\加工后的Excel表\\";
        String bearingName = bearing + ".xlsx";
        // 轴承对应的 对应工序
        String bearingCorrespondingProcess = "表面阳极";
        List<BomMaterial> bomBearingList = excelService.excelObjectList(BomMaterial.class, bearingPath, bearingName, false);

        List<ResultBom> resultBearingBomList = new ArrayList<>();
        Set<String> notBearingBomList = new HashSet<>();

        // 商品信息
        for (ResultErp resultErp : resultErpList) {
            String commodityCode = resultErp.getCommodityCode();
            // 去除空格
            commodityCode = commodityCode.replace(" ", "");
            boolean oneIG = commodityCode.charAt(0) == 'I' && commodityCode.charAt(1) == 'G';

            if (oneIG) {
                ResultBom resultBom = new ResultBom();
                String[] split = commodityCode.split("-");
                // IGH-S5M150-24-W-608
                for (int i = 0; i < bomBearingList.size(); i++) {
                    BomMaterial bomMaterial = bomBearingList.get(i);
                    String type = bomMaterial.getType();
                    if (split[4].equals(type)) {
                        // 加工件编码
                        resultBom.setWorkpieceCode(resultErp.getCommodityCode());
                        // 下级物料编码
                        resultBom.setSubordinateMaterialsCode(bomMaterial.getCommodityCode());
                        // 下级物料名称
                        resultBom.setSubordinateMaterialsName(bomMaterial.getCommodityName());
                        // 下级物料规格
                        resultBom.setSubordinateMaterialsSpecs(bomMaterial.getSpecs());
                        // 下级物料型号
                        resultBom.setSubordinateMaterialsType(bomMaterial.getType());
                        // 底数
                        resultBom.setBaseNumber("1");
                        if ("A".equals(split[3])) {
                            // 用量
                            resultBom.setDosage("1");
                        } else if ("B".equals(split[3]) || "W".equals(split[3])) {
                            // 用量
                            resultBom.setDosage("2");
                        }
                        // 单位
                        resultBom.setUnit(bomMaterial.getUnit());
                        // 损耗率
                        resultBom.setLossRate("0");
                        // 对应工序
                        resultBom.setCorrespondingProcess(bearingCorrespondingProcess);
                        resultBearingBomList.add(resultBom);
                        break;
                    }

                    // 如果此商品没找对应的Bom信息，可以保存一下数据，手动添加
                    if (i == bomBearingList.size() - 1) {
                        notBearingBomList.add(commodityCode);
                    }
                }
            }
        }

        log.info("商品数据集合大小 ==> {}", resultErpList.size());
        log.info(fileName + "对应BOM数据集合大小===" + bearing + " ==> {}", resultBearingBomList.size());
        log.info(fileName + "对应BOM信息残缺的数据集合大小===" + bearing + " ==> {}", notBearingBomList.size());
        log.info(fileName + "对应BOM信息残缺的数据集合===" + bearing + " ==> {}", JSON.toJSONString(notBearingBomList));

        Map<String, Object> map = new HashMap<>();
        map.put("resultBearingBomList", resultBearingBomList);
        map.put("resultNotBearingBomList", notBearingBomList);
        return map;
    }

    /**
     * ERP系统BOM表批量导入功能生成卡簧Excel表
     */
    public Map<String, Object> bomCirclipImportErp(List<ResultBom> resultBoms) throws Exception {

        String circlip = "卡簧";
        String circlipPath = "D:\\华链-胡健\\2024-01-16ERP商品录入功能\\加工后的Excel表\\";
        String circlipName = circlip + ".xlsx";
        // 卡簧对应的 对应工序
        String circlipCorrespondingProcess = "表面阳极";
        List<BomMaterial> bomcirclipList = excelService.excelObjectList(BomMaterial.class, circlipPath, circlipName, false);

        List<ResultBom> resultCirclipBomList = new ArrayList<>();
        Set<String> notCirclipBomList = new HashSet<>();

        for (ResultBom IgBom : resultBoms) {
            // IGH-S5M150-24-W-608
            String commodityCode = IgBom.getWorkpieceCode();
            String[] split = commodityCode.split("-");
            if ("W".equals(split[3])) {
                continue;
            }
            String subordinateMaterialsSpecs = IgBom.getSubordinateMaterialsSpecs();
            String bearingSpecs = subordinateMaterialsSpecs.substring(1, 3);
            boolean oneIG = commodityCode.charAt(0) == 'I' && commodityCode.charAt(1) == 'G';
            if (oneIG) {
                ResultBom resultBom = new ResultBom();
                for (int i = 0; i < bomcirclipList.size(); i++) {
                    BomMaterial bomMaterial = bomcirclipList.get(i);
                    String specs = bomMaterial.getSpecs();
                    if (bearingSpecs.equals(specs)) {
                        // 加工件编码
                        resultBom.setWorkpieceCode(IgBom.getWorkpieceCode());
                        // 下级物料编码
                        resultBom.setSubordinateMaterialsCode(bomMaterial.getCommodityCode());
                        // 下级物料名称
                        resultBom.setSubordinateMaterialsName(bomMaterial.getCommodityName());
                        // 下级物料规格
                        resultBom.setSubordinateMaterialsSpecs(bomMaterial.getSpecs());
                        // 下级物料型号
                        resultBom.setSubordinateMaterialsType(bomMaterial.getType());
                        // 底数
                        resultBom.setBaseNumber("1");
                        // 用量
                        resultBom.setDosage("1");
                        // 单位
                        resultBom.setUnit(bomMaterial.getUnit());
                        // 损耗率
                        resultBom.setLossRate("0");
                        // 对应工序
                        resultBom.setCorrespondingProcess(circlipCorrespondingProcess);
                        resultCirclipBomList.add(resultBom);
                        break;
                    }

                    // 如果此商品没找对应的Bom信息，可以保存一下数据，手动添加
                    if (i == bomcirclipList.size() - 1) {
                        notCirclipBomList.add(commodityCode);
                    }
                }
            }
        }

        log.info("商品数据集合大小 ==> {}", resultBoms.size());
        log.info("导入Erp系统文件对应BOM数据集合大小===" + circlip + " ==> {}", resultCirclipBomList.size());
        log.info("导入Erp系统文件对应BOM信息残缺的数据集合大小===" + circlip + " ==> {}", notCirclipBomList.size());
        log.info("导入Erp系统文件对应BOM信息残缺的数据集合===" + circlip + " ==> {}", JSON.toJSONString(notCirclipBomList));

        Map<String, Object> map = new HashMap<>();
        map.put("resultCirclipBomList", resultCirclipBomList);
        map.put("resultNotCirclipBomList", notCirclipBomList);
        return map;
    }

    /**
     * ERP系统BOM表批量导入功能生成胀套Excel表
     */
    public Map<String, Object> bomExpansionSleeveImportErp(String filePath, String fileName, HttpServletResponse response) throws Exception {

        // 商品数据集合
        List<ResultErp> resultErpList = excelService.excelObjectList(ResultErp.class, filePath, fileName, false);

        String expansionSleeve = "胀套";
        String expansionSleevePath = "D:\\华链-胡健\\2024-01-16ERP商品录入功能\\加工后的Excel表\\";
        String expansionSleeveName = expansionSleeve + ".xlsx";
        // 胀套对应的 对应工序
        String expansionSleeveCorrespondingProcess = "加工完成";
        List<BomMaterial> bomExpansionSleeveList = excelService.excelObjectList(BomMaterial.class, expansionSleevePath, expansionSleeveName, false);

        List<ResultBom> resultExpansionSleeveBomList = new ArrayList<>();
        Set<String> notExpansionSleeveBomList = new HashSet<>();

        for (ResultErp resultErp : resultErpList) {
            // PLH-S8M300-30-E-C-d15
            String commodityCode = resultErp.getCommodityCode();
            // 去除空格
            commodityCode = commodityCode.replace(" ", "");
            boolean onePL = commodityCode.charAt(0) == 'P' && commodityCode.charAt(1) == 'L';

            if (onePL) {
                ResultBom resultBom = new ResultBom();
                String[] split = commodityCode.split("-");
                for (int i = 0; i < bomExpansionSleeveList.size(); i++) {
                    BomMaterial bomMaterial = bomExpansionSleeveList.get(i);
                    String bomMaterialCommodityCode = bomMaterial.getCommodityCode();
                    String bomMaterialPL = bomMaterialCommodityCode.substring(3, 4);
                    String[] splitSplit = bomMaterialCommodityCode.split("-");
                    if ("A".equals(bomMaterialPL) && "A".equals(split[4])) {
                        if (splitSplit[1].equals(split[5])) {
                            // 加工件编码
                            resultBom.setWorkpieceCode(resultErp.getCommodityCode());
                            // 下级物料编码
                            resultBom.setSubordinateMaterialsCode(bomMaterial.getCommodityCode());
                            // 下级物料名称
                            resultBom.setSubordinateMaterialsName(bomMaterial.getCommodityName());
                            // 下级物料规格
                            resultBom.setSubordinateMaterialsSpecs(bomMaterial.getSpecs());
                            // 下级物料型号
                            resultBom.setSubordinateMaterialsType(bomMaterial.getType());
                            // 底数
                            resultBom.setBaseNumber("1");
                            // 用量
                            resultBom.setDosage("1");
                            // 单位
                            resultBom.setUnit(bomMaterial.getUnit());
                            // 损耗率
                            resultBom.setLossRate("0");
                            // 对应工序
                            resultBom.setCorrespondingProcess(expansionSleeveCorrespondingProcess);
                            resultExpansionSleeveBomList.add(resultBom);
                            break;
                        }
                    } else if ("C".equals(bomMaterialPL) && "C".equals(split[4])) {
                        String bomMaterialCommodityName = bomMaterial.getCommodityName();
                        String pl = bomMaterialCommodityName.substring(bomMaterialCommodityName.length() - 1);
                        if (pl.equals(split[3]) && splitSplit[1].equals(split[5])) {
                            // 加工件编码
                            resultBom.setWorkpieceCode(resultErp.getCommodityCode());
                            // 下级物料编码
                            resultBom.setSubordinateMaterialsCode(bomMaterial.getCommodityCode());
                            // 下级物料名称
                            resultBom.setSubordinateMaterialsName(bomMaterial.getCommodityName());
                            // 下级物料规格
                            resultBom.setSubordinateMaterialsSpecs(bomMaterial.getSpecs());
                            // 下级物料型号
                            resultBom.setSubordinateMaterialsType(bomMaterial.getType());
                            // 底数
                            resultBom.setBaseNumber("1");
                            // 用量
                            resultBom.setDosage("1");
                            // 单位
                            resultBom.setUnit(bomMaterial.getUnit());
                            // 损耗率
                            resultBom.setLossRate("0");
                            // 对应工序
                            resultBom.setCorrespondingProcess(expansionSleeveCorrespondingProcess);
                            resultExpansionSleeveBomList.add(resultBom);
                            break;
                        }
                    }

                    // 如果此商品没找对应的Bom信息，可以保存一下数据，手动添加
                    if (i == bomExpansionSleeveList.size() - 1) {
                        notExpansionSleeveBomList.add(commodityCode);
                    }
                }
            }
        }

        log.info("商品数据集合大小 ==> {}", resultErpList.size());
        log.info(fileName + "对应BOM数据集合大小===" + expansionSleeve + " ==> {}", resultExpansionSleeveBomList.size());
        log.info(fileName + "对应BOM信息残缺的数据集合大小===" + expansionSleeve + " ==> {}", notExpansionSleeveBomList.size());
        log.info(fileName + "对应BOM信息残缺的数据集合===" + expansionSleeve + " ==> {}", JSON.toJSONString(notExpansionSleeveBomList));

        Map<String, Object> map = new HashMap<>();
        map.put("resultExpansionSleeveBomList", resultExpansionSleeveBomList);
        map.put("resultNotExpansionSleeveBomList", notExpansionSleeveBomList);
        return map;
    }

    /**
     * ERP系统BOM表批量导入功能生成[材料、挡圈]Excel表
     * 材料表、挡圈表
     */
    @Override
    public String bomImportErp(String materialFilePath, String materialFileName, String ringFilePath, String ringFileName, HttpServletResponse response) throws Exception {

        Map<String, Object> materialMap = bomMaterialImportErp(materialFilePath, materialFileName, response);
        List<ResultBom> resultBomMaterialList = (List<ResultBom>) materialMap.get("resultBomMaterialList");
        Set<String> resultNotBomMaterialList = (Set<String>) materialMap.get("resultNotBomMaterialList");

        Map<String, Object> ringMap = bomRingImportErp(ringFilePath, ringFileName, response);
        List<ResultBom> resultBomRingList = (List<ResultBom>) ringMap.get("resultBomRingList");
        Set<String> resultNotBomRingList = (Set<String>) ringMap.get("resultNotBomRingList");

        Map<String, Object> bearingMap = bomBearingImportErp(ringFilePath, ringFileName, response);
        List<ResultBom> resultBearingBomList = (List<ResultBom>) bearingMap.get("resultBearingBomList");
        Set<String> resultNotBearingBomList = (Set<String>) bearingMap.get("resultNotBearingBomList");

        Map<String, Object> circlipMap = bomCirclipImportErp(resultBearingBomList);
        List<ResultBom> resultCirclipBomList = (List<ResultBom>) circlipMap.get("resultCirclipBomList");
        Set<String> resultNotCirclipBomList = (Set<String>) circlipMap.get("resultNotCirclipBomList");

        Map<String, Object> expansionSleeveMap = bomExpansionSleeveImportErp(ringFilePath, ringFileName, response);
        List<ResultBom> resultExpansionSleeveBomList = (List<ResultBom>) expansionSleeveMap.get("resultExpansionSleeveBomList");
        Set<String> resultNotExpansionSleeveBomList = (Set<String>) expansionSleeveMap.get("resultNotExpansionSleeveBomList");

        List<ResultBom> resultBomListOne = Stream.concat(resultBomMaterialList.stream(), resultBomRingList.stream())
                .sorted()
                .collect(Collectors.toList());

        List<ResultBom> resultBomListTwo = Stream.concat(resultBomListOne.stream(), resultBearingBomList.stream())
                .sorted()
                .collect(Collectors.toList());

        List<ResultBom> resultBomListThree = Stream.concat(resultBomListTwo.stream(), resultCirclipBomList.stream())
                .sorted()
                .collect(Collectors.toList());

        List<ResultBom> resultBomListFour = Stream.concat(resultBomListThree.stream(), resultExpansionSleeveBomList.stream())
                .sorted()
                .collect(Collectors.toList());

        Set<String> all = new HashSet<>();
        all.addAll(resultNotBomMaterialList);
        all.addAll(resultNotBomRingList);
        all.addAll(resultNotBearingBomList);
        all.addAll(resultNotCirclipBomList);
        all.addAll(resultNotExpansionSleeveBomList);

        log.info("BOM数据集合大小 ==> {}", resultBomListFour.size());
        log.info("有问题BOM数据集合 ==> {}", JSON.toJSONString(all));
        return excelService.wired(resultBomListFour, ResultBom.class, materialFileName.split("\\.")[0] + "对应BOM数据", response);
    }

    /**
     * 根据商品编码生成ERP系统具体的所需要的商品信息
     */
    @Override
    public String generateErpCommodityCode(String filePath, String fileName, HttpServletResponse response) throws Exception {

        List<ResultErp> importErpList = excelService.excelObjectList(ResultErp.class, filePath, fileName, false);

        List<ResultErp> resultErpList = new ArrayList<>();

        // 查询不到的型号集合
        List<String> problemString = new ArrayList<>();
        List<String> emptyString = new ArrayList<>();

        // 根据商品编码查询商品信息
        for (int i = 0; i < importErpList.size(); i++) {
            String commodityCode = importErpList.get(i).getCommodityCode();
            String originalCommodityCode = importErpList.get(i).getCommodityCode();
            if (commodityCode.contains(" ")) {
                emptyString.add(commodityCode);
            }
            // 去除空格
            commodityCode = commodityCode.replace(" ", "");

            AjaxResult ajaxResult = null;
            ResultTimingPulleyPrice resultTimingPulleyPrice = null;

            String[] split = null;
            // 同步轮轴孔类型
            String tpAxleHoleType = null;
            // 同步轮材质
            String materialMark = null;
            // 齿形
            String tooth = null;
            // 同步轮代表的型号 TP
            String tp = null;
            // 同步轮形状
            String tpShape = null;

            // 首先判定是否为 同步轮 还是 惰轮 还是 胀紧套
            log.info("商品型号编码 ==> {}", commodityCode);
            boolean oneTP = commodityCode.charAt(0) == 'T' && commodityCode.charAt(1) == 'P';
            boolean twoTP = commodityCode.contains("Z-") && commodityCode.charAt(2) == 'T' && commodityCode.charAt(3) == 'P';
            boolean threeTP = commodityCode.contains("FB-") && commodityCode.charAt(3) == 'T' && commodityCode.charAt(4) == 'P';

            boolean oneIG = commodityCode.charAt(0) == 'I' && commodityCode.charAt(1) == 'G';
            boolean onePL = commodityCode.charAt(0) == 'P' && commodityCode.charAt(1) == 'L';

            ResultErp resultErp = new ResultErp();
            // 商品大类
            String oneLevel = "";
            // 商品小类
            String twoLevel = "";
            // 三级分类
            String threeLevel = null;

            if (oneTP || twoTP || threeTP) {
                // 同步轮
                // 正常 TPC-H5M250-50-A-N-d35
                // 非标 Z-TPH-S5MA32-50-B-N-d20-FC80.5
                // 非标 FB-TPH-T5100-18-A-H-d14

                if (oneTP || threeTP) {
                    if (threeTP) {


                        commodityCode = commodityCode.substring(3);
                    }
                    ajaxResult = tpCostPrice(commodityCode, null, null, false, false, "13711851155");
                    if ("200".equals(ajaxResult.get("code").toString())) {
                        resultTimingPulleyPrice = (ResultTimingPulleyPrice) ajaxResult.get("data");

                        // TPC-H5M250-50-A-N-d35
                        split = commodityCode.split("-");
                        // 同步轮轴孔类型
                        tpAxleHoleType = split[4];
                        // 同步轮材质 特殊材质
                        if ("HK".equals(split[0].substring(split[0].length() - 2))) {
                            materialMark = "HK";
                        } else {
                            materialMark = split[0].substring(split[0].length() - 1);
                        }
                        // 齿形
                        tooth = split[1].substring(0, split[1].length() - 3);
                        // 同步轮代表的型号 TP
                        tp = split[0].substring(0, 2);
                        // 同步轮形状
                        tpShape = split[3];
                    } else {
                        problemString.add(commodityCode);
                        continue;
                    }
                } else if (twoTP) {
                    ajaxResult = tpCostPrice(commodityCode, null, null, false, true, "13711851155");
                    if ("200".equals(ajaxResult.get("code").toString())) {
                        resultTimingPulleyPrice = (ResultTimingPulleyPrice) ajaxResult.get("data");

                        // Z-TPH-S5MA32-50-B-N-d20-FC80.5
                        // Z-TPH-S5MA32-25-A-Y-d13-Q19-R19-S10-T10-FC41

                        split = commodityCode.split("-");
                        // 同步轮轴孔类型
                        tpAxleHoleType = split[5];
                        // 同步轮材质 特殊材质
                        if ("HK".equals(split[1].substring(split[1].length() - 2))) {
                            materialMark = "HK";
                        } else {
                            materialMark = split[1].substring(split[1].length() - 1);
                        }
                        // 齿形
                        tooth = split[2].substring(0, split[2].length() - 3);
                        // 同步轮代表的型号 TP
                        tp = split[1].substring(0, 2);
                        // 同步轮形状
                        tpShape = split[4];
                    } else {
                        problemString.add(commodityCode);
                        continue;
                    }
                }

                // 商品大类
                oneLevel = "01 同步轮";
                // 三级分类
                threeLevel = tp + "-" + tpShape + "-" + tpAxleHoleType;
                if ("H".equals(tpAxleHoleType) || "V".equals(tpAxleHoleType) | "Y".equals(tpAxleHoleType)) {
                    // 滚齿
                    resultErp.setHobbing("4");
                    // 压挡圈
                    resultErp.setPressureRetainingRing("5");
                } else if ("P".equals(tpAxleHoleType)) {
                    // 滚齿
                    resultErp.setHobbing("4");
                    // 钻攻
                    resultErp.setDrillingAttack("5");
                    // 压挡圈
                    resultErp.setPressureRetainingRing("6");
                } else if ("N".equals(tpAxleHoleType) || "C".equals(tpAxleHoleType)) {
                    // 滚齿
                    resultErp.setHobbing("4");
                    // 钻攻
                    resultErp.setDrillingAttack("5");
                    // 拉键槽
                    resultErp.setPullingKeyGroove("6");
                    // 压挡圈
                    resultErp.setPressureRetainingRing("7");
                } else {
                    // 滚齿
                    resultErp.setHobbing("4");
                    // 钻攻
                    resultErp.setDrillingAttack("5");
                    // 线割
                    resultErp.setSurfaceWireCut("6");
                    // 压挡圈
                    resultErp.setPressureRetainingRing("7");
                }
            } else if (oneIG) {
                // IGH-S5M150-24-W-608

                ajaxResult = igCostPrice(commodityCode, null, null, false, false, "13711851155");
                if ("200".equals(ajaxResult.get("code").toString())) {
                    resultTimingPulleyPrice = (ResultTimingPulleyPrice) ajaxResult.get("data");

                    split = commodityCode.split("-");
                    // 同步惰轮 特殊材质
                    if ("HK".equals(split[0].substring(split[0].length() - 2))) {
                        materialMark = "HK";
                    } else {
                        materialMark = split[0].substring(split[0].length() - 1);
                    }
                    // 齿形
                    tooth = split[1].substring(0, split[1].length() - 3);
                    // 商品大类
                    oneLevel = "01 同步轮";
                } else {
                    problemString.add(commodityCode);
                    continue;
                }
                // 滚齿
                resultErp.setHobbing("4");
                // 压挡圈
                resultErp.setPressureRetainingRing("5");
            } else if (onePL) {
                // PLC-S5M150-34-E-C-d14

                split = commodityCode.split("-");
                // 同步轮胀紧套 特殊材质
                if ("HK".equals(split[0].substring(split[0].length() - 2))) {
                    materialMark = "HK";
                } else {
                    materialMark = split[0].substring(split[0].length() - 1);
                }
                // 齿形
                tooth = split[1].substring(0, split[1].length() - 3);
                // 商品大类
                oneLevel = "01 同步轮";

                // 滚齿
                resultErp.setHobbing("4");
                // 压挡圈
                resultErp.setPressureRetainingRing("5");
            } else {
                problemString.add(commodityCode);
                continue;
            }

            // 商品小类
            if (ObjectUtils.equals("H3M", tooth)) {
                twoLevel = "17 齿形H3M";
            } else if (ObjectUtils.equals("H5M", tooth)) {
                twoLevel = "18 齿形H5M";
            } else if (ObjectUtils.equals("H8M", tooth)) {
                twoLevel = "19 齿形H8M";
            } else if (ObjectUtils.equals("S2M", tooth)) {
                twoLevel = "09 齿形S2M";
            } else if (ObjectUtils.equals("S3M", tooth)) {
                twoLevel = "10 齿形S3M";
            } else if (ObjectUtils.equals("S5M", tooth)) {
                twoLevel = "11 齿形S5M";
            } else if (ObjectUtils.equals("S8M", tooth)) {
                twoLevel = "12 齿形S8M";
            } else if (ObjectUtils.equals("T5", tooth)) {
                twoLevel = "05 齿形T5";
            } else if (ObjectUtils.equals("T10", tooth)) {
                twoLevel = "06 齿形T10";
            } else if (ObjectUtils.equals("MXL", tooth)) {
                twoLevel = "01 齿形MXL";
            } else if (ObjectUtils.equals("XL", tooth)) {
                twoLevel = "02 齿形XL";
            } else if (ObjectUtils.equals("L", tooth)) {
                twoLevel = "03 齿形L";
            } else if (ObjectUtils.equals("H", tooth)) {
                twoLevel = "04 齿形H";
            }

            resultErp.setOneLevel(oneLevel);
            resultErp.setTwoLevel(twoLevel);
            resultErp.setThreeLevel(threeLevel);

            // 切料
            resultErp.setCutting("1");
            // 车A面
            resultErp.setVehicleA("2");
            // 车B面
            resultErp.setVehicleB("3");

            // 表面处理
            int number = Integer.parseInt(resultErp.getPressureRetainingRing());
            number++;
            String surface = Integer.toString(number);
            if ("A".equals(materialMark)) {
                resultErp.setSurfaceNot(surface);
            } else if ("H".equals(materialMark)) {
                resultErp.setSurfaceAnode(surface);
                resultErp.setSurfaceTreatmentMethod("本色阳极氧化");
            } else if ("HK".equals(materialMark)) {
                resultErp.setSurfaceAnodeColor(surface);
                resultErp.setSurfaceTreatmentMethod("黑色阳极氧化");
            } else if ("K".equals(materialMark)) {
                resultErp.setSurfaceOther(surface);
                resultErp.setSurfaceTreatmentMethod("硬质阳极氧化");
            } else if ("R".equals(materialMark)) {
                resultErp.setSurfaceNickeling(surface);
                resultErp.setSurfaceTreatmentMethod("镀镍");
            } else if ("F".equals(materialMark)) {
                resultErp.setSurfaceNot(surface);
            } else if ("C".equals(materialMark)) {
                resultErp.setSurfaceTurnBlack(surface);
                resultErp.setSurfaceTreatmentMethod("发黑");
            } else if ("D".equals(materialMark)) {
                resultErp.setSurfaceNickeling(surface);
                resultErp.setSurfaceTreatmentMethod("镀镍");
            } else if ("S".equals(materialMark)) {
                resultErp.setSurfaceNot(surface);
            }

            // 加工完成
            resultErp.setProcessingCompleted(Integer.toString(Integer.parseInt(surface) + 1));

            if (ObjectUtils.isNotEmpty(resultTimingPulleyPrice)) {
                // 单价
                resultErp.setRetailPrice(resultTimingPulleyPrice.getRetailPrice());
            }

            resultErp.setProductionType("加工");

            resultErp.setCommodityName("同步轮");
            resultErp.setUnit("PCS");
            resultErp.setCostCalculationMethod("移动加权法");

            resultErp.setCommodityCode(originalCommodityCode);
            resultErp.setType(originalCommodityCode);
            resultErpList.add(resultErp);
        }

        log.info("往ERP系统导入商品数据的大小 ==> {}", resultErpList.size());
        log.info("有问题的商品型号数据 ==> {}", JSON.toJSONString(problemString));
        log.info("有空格的商品型号数据 ==> {}", JSON.toJSONString(emptyString));
        return excelService.wired(resultErpList, ResultErp.class, "导入Erp系统文件", response);
    }

    /**
     * 同步轮类型转换Excel
     */
    @Override
    public String typeConvertExcel(String filePath, String fileName, HttpServletResponse response) throws Exception {

        List<ResultConvert> convertList = excelService.excelObjectList(ResultConvert.class, filePath, fileName, false);

        for (int i = 0; i < convertList.size(); i++) {
            ResultConvert resultConvert = convertList.get(i);
            AjaxResult ajaxResult = strangeTypeConvertWebsite(resultConvert.getOtherCommodity());
            Integer code = (Integer) ajaxResult.get("code");
            if (code == 200) {
                String commodity = ajaxResult.get("data").toString();
                convertList.get(i).setCommodity(commodity);
            }
        }
        return excelService.wired(convertList, ResultConvert.class, "excelName", response);
    }

    /**
     * 同步轮价格查询
     */
    @Override
    public String typePriceExcel(String filePath, String fileName, HttpServletResponse response) throws Exception {

        List<ResultConvert> convertList = excelService.excelObjectList(ResultConvert.class, filePath, fileName, false);
        for (int i = 0; i < convertList.size(); i++) {
            ResultConvert resultConvert = convertList.get(i);
            if (ObjectUtils.isEmpty(resultConvert.getCommodity())) {
                continue;
            }
            AjaxResult ajaxResult = costPrice(resultConvert.getCommodity(), null, null, false, "13711851155");
            Integer code = (Integer) ajaxResult.get("code");
            if (code == 200) {
                ResultTimingPulleyPrice resultTimingPulleyPrice = (ResultTimingPulleyPrice) ajaxResult.get("data");
                int num = Integer.parseInt(resultConvert.getNum());
                if (num <= 5) {
                    convertList.get(i).setPrice(resultTimingPulleyPrice.getTaxNum5());
                } else if (num <= 10) {
                    convertList.get(i).setPrice(resultTimingPulleyPrice.getTaxNum10());
                } else if (num <= 20) {
                    convertList.get(i).setPrice(resultTimingPulleyPrice.getTaxNum20());
                } else if (num <= 50) {
                    convertList.get(i).setPrice(resultTimingPulleyPrice.getTaxNum50());
                } else if (num > 80 && num <= 400) {
                    convertList.get(i).setPrice(resultTimingPulleyPrice.getTaxNum100());
                } else if (num > 400 && num <= 500) {
                    convertList.get(i).setPrice(resultTimingPulleyPrice.getTaxNum500());
                } else {
                    convertList.get(i).setPrice(resultTimingPulleyPrice.getTaxNum1000());
                }
            }
        }
        return excelService.wired(convertList, ResultConvert.class, "excelName", response);
    }

    /**
     * 采购订单挡边价格补充
     */
    @Override
    public String purchaseFlangeProblem(String filePath, String fileName, HttpServletResponse response) throws Exception {

        List<PurchaseReceipt> purchaseReceiptList = excelService.excelObjectList(PurchaseReceipt.class, filePath, fileName, false);

        List<String> notPurchaseReceiptList = new ArrayList<>();

        for (int i = 0; i < purchaseReceiptList.size(); i++) {

            PurchaseReceipt purchaseReceipt = purchaseReceiptList.get(i);
            String code = purchaseReceipt.getCode();
            String productName = purchaseReceipt.getProductName();

            HlFlange hlFlange = hlFlangeService.selectOne(purchaseReceipt.getSpecs());
            if (ObjectUtils.isEmpty(hlFlange)) {
                notPurchaseReceiptList.add(purchaseReceipt.getSpecs());
                continue;
            }

            if (code.contains("铝") || productName.contains("铝")) {
                if (code.contains("1.5") || productName.contains("1.5")) {
                    purchaseReceiptList.get(i).setPrice(hlFlange.getOneFiveAluminumAlloy());
                    purchaseReceiptList.get(i).setMoney(new BigDecimal(purchaseReceipt.getDeliveryQuantity()).multiply(new BigDecimal(hlFlange.getOneFiveAluminumAlloy())).setScale(1, RoundingMode.HALF_UP).toString());
                }
            } else if (code.contains("铁") || productName.contains("铁")) {
                if (code.contains("1.5") || productName.contains("1.5")) {
                    purchaseReceiptList.get(i).setPrice(hlFlange.getOneFiveIronNickelPlating());
                    purchaseReceiptList.get(i).setMoney(new BigDecimal(purchaseReceipt.getDeliveryQuantity()).multiply(new BigDecimal(hlFlange.getOneFiveIronNickelPlating())).setScale(1, RoundingMode.HALF_UP).toString());
                }
            }
        }

        log.info("未查询到的挡边信息 ==> {}", JSON.toJSONString(notPurchaseReceiptList));
        return excelService.wired(purchaseReceiptList, PurchaseReceipt.class, "采购订单挡边价格补充", response);
    }

    /**
     * 采购订单入库Excel表生成
     */
    @Override
    public String purchaseReceipt(String filePath, String fileName, HttpServletResponse response) throws Exception {

        List<PurchaseReceipt> purchaseReceiptList = excelService.excelObjectList(PurchaseReceipt.class, filePath, fileName, false);

        // 挡圈
        String ring = "挡圈";
        String ringPath = "D:\\华链-胡健\\2024-01-16ERP商品录入功能\\加工后的Excel表\\";
        String ringName = "挡圈.xlsx";
        List<BomMaterial> bomRingList = excelService.excelObjectList(BomMaterial.class, ringPath, ringName, false);

        // 整个 bomMaterialList 集合拆分成 铝 和 铁
        List<BomMaterial> aluminiumBomMaterialList = bomRingList.stream()
                .filter(bomMaterial -> bomMaterial.getType().contains("铝"))
                .collect(Collectors.toList());
        List<BomMaterial> ironBomMaterialList = bomRingList.stream()
                .filter(bomMaterial -> bomMaterial.getType().contains("铁"))
                .collect(Collectors.toList());

        List<PurchaseReceiptTemplate> purchaseReceiptTemplateList = new ArrayList<>();
        List<PurchaseReceipt> notPurchaseReceipts = new ArrayList<>();
        List<String> notPurchaseReceiptList = new ArrayList<>();

        for (int i = 0; i < purchaseReceiptList.size(); i++) {
            PurchaseReceipt purchaseReceipt = purchaseReceiptList.get(i);
            String code = purchaseReceipt.getCode();
            String productName = purchaseReceipt.getProductName();

            String purchaseReceiptSpecs = purchaseReceipt.getSpecs();
            String[] specsSplit;

            if (purchaseReceiptSpecs.contains("X")) {
                specsSplit = purchaseReceiptSpecs.split("X");
            } else if (purchaseReceiptSpecs.contains("x")) {
                specsSplit = purchaseReceiptSpecs.split("x");
            } else {
                notPurchaseReceiptList.add(purchaseReceiptSpecs);
                break;
            }

            boolean contains = false;
            StringBuilder stringBuilder = new StringBuilder();
            // φ15*φ8*1.2
            if (specsSplit.length == 2) {
                stringBuilder.append("φ").append(specsSplit[0]).append("*φ").append(specsSplit[1]);
                if (code.contains("1.5") || productName.contains("1.5")) {
                    stringBuilder.append("*1.5");
                } else if (code.contains("1.2") || productName.contains("1.2")) {
                    stringBuilder.append("*1.2");
                }
            } else if (specsSplit.length == 3) {
                stringBuilder.append("φ").append(specsSplit[0]).append("*φ").append(specsSplit[1]);
                if ("1".equals(specsSplit[2])) {
                    stringBuilder.append("*1.2");
                } else {
                    stringBuilder.append("*").append(specsSplit[2]);
                }
            }

            String string = stringBuilder.toString();
            log.info("拼接后的规格 ==> {}", string);

            if (code.contains("铝") || productName.contains("铝")) {
                for (BomMaterial bomMaterial : aluminiumBomMaterialList) {
                    if (bomMaterial.getSpecs().equals(string)) {
                        contains = true;

                        PurchaseReceiptTemplate purchaseReceiptTemplate = new PurchaseReceiptTemplate();
                        purchaseReceiptTemplate.setCommodityCode(bomMaterial.getCommodityCode());
                        purchaseReceiptTemplate.setCommodityName(bomMaterial.getCommodityName());
                        purchaseReceiptTemplate.setCommoditySpecs(bomMaterial.getSpecs());
                        purchaseReceiptTemplate.setCommodityType(bomMaterial.getCommodityCode());
                        purchaseReceiptTemplate.setNum(purchaseReceipt.getDeliveryQuantity());
                        purchaseReceiptTemplate.setUnit(purchaseReceipt.getUnit());
                        purchaseReceiptTemplate.setPrice(purchaseReceipt.getPrice());
                        purchaseReceiptTemplate.setSubtotal(purchaseReceipt.getMoney());
                        purchaseReceiptTemplate.setCustomerCode(purchaseReceipt.getCustomerName());
                        purchaseReceiptTemplate.setAttachmentInformation(purchaseReceipt.getRemarks());
                        purchaseReceiptTemplate.setDate(purchaseReceipt.getDate());
                        purchaseReceiptTemplateList.add(purchaseReceiptTemplate);
                        break;
                    }
                }
            } else if (code.contains("铁") || productName.contains("铁")) {
                for (BomMaterial bomMaterial : ironBomMaterialList) {
                    if (bomMaterial.getSpecs().equals(string)) {
                        contains = true;

                        PurchaseReceiptTemplate purchaseReceiptTemplate = new PurchaseReceiptTemplate();
                        purchaseReceiptTemplate.setCommodityCode(bomMaterial.getCommodityCode());
                        purchaseReceiptTemplate.setCommodityName(bomMaterial.getCommodityName());
                        purchaseReceiptTemplate.setCommoditySpecs(bomMaterial.getSpecs());
                        purchaseReceiptTemplate.setCommodityType(bomMaterial.getCommodityCode());
                        purchaseReceiptTemplate.setNum(purchaseReceipt.getDeliveryQuantity());
                        purchaseReceiptTemplate.setUnit(purchaseReceipt.getUnit());
                        purchaseReceiptTemplate.setPrice(purchaseReceipt.getPrice());
                        purchaseReceiptTemplate.setSubtotal(purchaseReceipt.getMoney());
                        purchaseReceiptTemplate.setCustomerCode(purchaseReceipt.getCustomerName());
                        purchaseReceiptTemplate.setAttachmentInformation(purchaseReceipt.getRemarks());
                        purchaseReceiptTemplate.setDate(purchaseReceipt.getDate());
                        purchaseReceiptTemplateList.add(purchaseReceiptTemplate);
                        break;
                    }
                }
            }

            if (!contains) {
                purchaseReceipt.setRemarks(string);
                notPurchaseReceipts.add(purchaseReceipt);
                notPurchaseReceiptList.add(purchaseReceiptSpecs);
            }
        }
        log.info("有问题的Excel表规格 ==> {}", JSON.toJSONString(notPurchaseReceiptList));

        return excelService.wired(purchaseReceiptTemplateList, PurchaseReceiptTemplate.class, "采购订单挡边库存", response);
    }

    /**
     * 怡和达带齿惰轮导入数据库
     */
    @Override
    public AjaxResult yiHeDaIg(String filePath, String fileName, HttpServletResponse response) {

        List<HlOtherCommodityDetails> hlOtherCommodityDetailsList = excelService.excelObjectList(HlOtherCommodityDetails.class, filePath, fileName, false);

        List<HlOtherCommodityDetails> hlOtherCommodityDetailsArrayList = new ArrayList<>();

        for (int i = 0; i < hlOtherCommodityDetailsList.size(); i++) {
            HlOtherCommodityDetails hlOtherCommodityDetails = hlOtherCommodityDetailsList.get(i);
            String code = hlOtherCommodityDetails.getCode();
            String bearingLayout = hlOtherCommodityDetails.getBearingLayout();
            String bearingType = hlOtherCommodityDetails.getBearingType();
            String teeth = hlOtherCommodityDetails.getTeeth();
            String bandwidth = hlOtherCommodityDetails.getBandwidth();

            String[] codeSplit = code.split("-");
            String[] bearingLayoutSplit = bearingLayout.split("-");
            String[] bearingTypeSplit = bearingType.split("-");
            String[] bandwidthSplit = bandwidth.split("-");

            HlOtherCommodityDetails otherCommodityDetails;
            for (String codeReplace : codeSplit) {
                if (bandwidthSplit.length > 1) {
                    A: for (int ii = 0; ii < bandwidthSplit.length; ii++) {
                        if (bearingTypeSplit.length > 1) {
                            if (bearingLayoutSplit.length > 1) {
                                otherCommodityDetails = new HlOtherCommodityDetails();
                                otherCommodityDetails.setCode(codeReplace);
                                otherCommodityDetails.setTeeth(teeth);
                                otherCommodityDetails.setBandwidth(bandwidthSplit[ii]);
                                otherCommodityDetails.setBearingType(bearingTypeSplit[ii]);
                                otherCommodityDetails.setBearingLayout(bearingLayoutSplit[ii]);
                                hlOtherCommodityDetailsArrayList.add(otherCommodityDetails);
                            } else {
                                otherCommodityDetails = new HlOtherCommodityDetails();
                                otherCommodityDetails.setCode(codeReplace);
                                otherCommodityDetails.setTeeth(teeth);
                                otherCommodityDetails.setBandwidth(bandwidthSplit[ii]);
                                otherCommodityDetails.setBearingType(bearingTypeSplit[ii]);
                                otherCommodityDetails.setBearingLayout(bearingLayout);
                                hlOtherCommodityDetailsArrayList.add(otherCommodityDetails);
                            }
                        } else {
                            otherCommodityDetails = new HlOtherCommodityDetails();
                            otherCommodityDetails.setCode(codeReplace);
                            otherCommodityDetails.setTeeth(teeth);
                            otherCommodityDetails.setBandwidth(bandwidthSplit[ii]);
                            otherCommodityDetails.setBearingType(bearingType);
                            otherCommodityDetails.setBearingLayout(bearingLayout);
                            hlOtherCommodityDetailsArrayList.add(otherCommodityDetails);
                        }
                    }
                } else {
                    otherCommodityDetails = new HlOtherCommodityDetails();
                    otherCommodityDetails.setCode(codeReplace);
                    otherCommodityDetails.setTeeth(teeth);
                    otherCommodityDetails.setBandwidth(bandwidth);
                    otherCommodityDetails.setBearingType(bearingType);
                    otherCommodityDetails.setBearingLayout(bearingLayout);
                    hlOtherCommodityDetailsArrayList.add(otherCommodityDetails);
                }
            }
        }
        hlOtherCommodityDetailsService.insertList(hlOtherCommodityDetailsArrayList);
        return AjaxResult.success();
    }

    /**
     * 怡和达同步轮类型转换网站
     */
    @Override
    public AjaxResult yiHeDaTypeConvertWebsite(String yiHeDaTypeCommodity) {
        // 去除空格
        yiHeDaTypeCommodity = yiHeDaTypeCommodity.replace(" ", "");
        log.info("怡和达商品编码 ==> {}", yiHeDaTypeCommodity);
        String[] splitSplit = yiHeDaTypeCommodity.split("-");

        // 查询其他型号表
        HlOtherCommodity replace = new HlOtherCommodity();
        replace.setCode(splitSplit[0]);
        replace.setMerchantCode("YiHeDa");
        HlOtherCommodity hlOtherCommodity = hlOtherCommodityService.selectOne(replace);
        if (ObjectUtils.isNotEmpty(hlOtherCommodity)) {
            StringBuilder commodity = new StringBuilder(hlOtherCommodity.getTpType() + hlOtherCommodity.getMaterialMark());

            ResultTimingPulleyPrice resultTimingPulleyPrice = new ResultTimingPulleyPrice();
            if ("TP".equals(hlOtherCommodity.getTpType())) {
                if ("EBD01".equals(splitSplit[0])) {
                    commodity.append("-").append(splitSplit[2]);
                    commodity.append("-").append(splitSplit[1]);
                    for (int ii = 3; ii < splitSplit.length; ii++) {
                        commodity.append("-").append(splitSplit[ii]);
                    }
                } else {
                    for (int ii = 1; ii < splitSplit.length; ii++) {
                        commodity.append("-").append(splitSplit[ii]);
                    }
                }

            }
            else if ("IG".equals(hlOtherCommodity.getTpType())) {
                HlOtherCommodityDetails otherCommodityDetails = new HlOtherCommodityDetails();
                otherCommodityDetails.setCode(splitSplit[0]);
                otherCommodityDetails.setTeeth(splitSplit[1]);
                otherCommodityDetails.setBandwidth(splitSplit[2]);
                HlOtherCommodityDetails hlOtherCommodityDetails = hlOtherCommodityDetailsService.selectOne(otherCommodityDetails, "IG");

                String one = splitSplit[1];
                String two = splitSplit[2];

                splitSplit[1] = two;
                splitSplit[2] = one;
                // EVD21-25-S3M100-FC25
                // IGH-S3M100-25-FC25-W-696
                if (splitSplit.length <= 3) {
                    for (int ii = 1; ii < splitSplit.length; ii++) {
                        commodity.append("-").append(splitSplit[ii]);
                    }
                    if (ObjectUtils.isNotEmpty(hlOtherCommodityDetails)) {
                        commodity.append("-").append(hlOtherCommodityDetails.getBearingLayout()).append("-").append(hlOtherCommodityDetails.getBearingType());
                    }
                } else {
                    for (int ii = 1; ii < 3; ii++) {
                        commodity.append("-").append(splitSplit[ii]);
                    }
                    if (ObjectUtils.isNotEmpty(hlOtherCommodityDetails)) {
                        commodity.append("-").append(hlOtherCommodityDetails.getBearingLayout()).append("-").append(hlOtherCommodityDetails.getBearingType());
                    }
                    for (int ii = 3; ii < splitSplit.length; ii++) {
                        commodity.append("-").append(splitSplit[ii]);
                    }
                }
            }
            else if ("PL".equals(hlOtherCommodity.getTpType())) {

                // APZAA-S5M150-36-F-d12
                commodity.append("-").append(splitSplit[1]).append("-").append(splitSplit[2]).append("-").append(splitSplit[3]).append("-").append(hlOtherCommodity.getBandwidth())
                        .append("-").append(splitSplit[4]);
            }
            else if (hlOtherCommodity.getTpType().contains("TG")) {

                // EVF11-W32-D45 = TGNH-D45-T32-W-6201
                // ENG21-D50-T21 = TGRC-D50-T21-W-6001-r0.3
                // ENG04-D20-T16 = TGTH-D20-T16-W-625-t1
                // EVF71-W15-D30 = TGTH-D30-T11-A-698-t2
                // EVF31-W11-D15 = TGTH-D15-T7-W-675-t2

                HlOtherCommodityDetails otherCommodityDetails = new HlOtherCommodityDetails();
                otherCommodityDetails.setCode(splitSplit[0]);
                otherCommodityDetails.setTeeth(splitSplit[1].substring(1));
                otherCommodityDetails.setShaftDiameter(splitSplit[2].substring(1));
                HlOtherCommodityDetails hlOtherCommodityDetails = hlOtherCommodityDetailsService.selectOne(otherCommodityDetails, "TG");

                BigDecimal L = new BigDecimal(0);
                if (ObjectUtils.isNotEmpty(hlOtherCommodityDetails.getBandwidth())) {
                    L = new BigDecimal(hlOtherCommodityDetails.getBandwidth());
                }

                // 注意TGU 的 W 的 D 很特殊
                if (splitSplit[1].charAt(0) == 'D' && splitSplit[2].charAt(0) == 'T') {
                    splitSplit[1] = splitSplit[1].replaceAll("[^0-9]", "");
                    splitSplit[2] = splitSplit[2].replaceAll("[^0-9]", "");
                    commodity.append("-D").append(splitSplit[1]).append("-T").append(splitSplit[2]);
                    if ("TGT".equals(hlOtherCommodity.getTpType())) {
                        L = L.subtract(new BigDecimal(splitSplit[2])).divide(BigDecimal.valueOf(2), 5, RoundingMode.HALF_UP).stripTrailingZeros();
                    }
                } else if (splitSplit[1].charAt(0) == 'W' && splitSplit[2].charAt(0) == 'D') {
                    splitSplit[1] = splitSplit[1].replaceAll("[^0-9]", "");
                    splitSplit[2] = splitSplit[2].replaceAll("[^0-9]", "");

                    if ("TGT".equals(hlOtherCommodity.getTpType())) {
                        splitSplit[1] = new BigDecimal(splitSplit[1]).subtract(L.multiply(BigDecimal.valueOf(2))).stripTrailingZeros().toString();
                    }
                    commodity.append("-D").append(splitSplit[2]).append("-T").append(splitSplit[1]);
                }

                if (ObjectUtils.isNotEmpty(hlOtherCommodityDetails)) {
                    commodity.append("-").append(hlOtherCommodityDetails.getBearingLayout()).append("-").append(hlOtherCommodityDetails.getBearingType());
                }

                if ("TGT".equals(hlOtherCommodity.getTpType())) {
                    commodity.append("-t").append(L);
                } else if ("TGR".equals(hlOtherCommodity.getTpType())) {
                    commodity.append("-r").append(L);
                }

                for (int i = 3; i < splitSplit.length; i++) {
                    commodity.append("-").append(splitSplit[i]);
                }
            }
            else if ("ETP".equals(hlOtherCommodity.getTpType())) {
                // EDA01-30-S3M100-d8 = ETPH-S3M100-30-d8

                commodity.append("-").append(splitSplit[2]).append("-").append(splitSplit[1]).append("-").append(splitSplit[3]);
            }
            log.info("转换后的商品编码 ==> {}", commodity.toString());
            return AjaxResult.success("操作成功", typeSpecialCharacter(commodity.toString()));
        } else {
            return AjaxResult.error("未查到具体型号");
        }

    }

    /**
     * 米思米同步轮导入数据库
     */
    @Override
    public AjaxResult miSiMiTp(String filePath, String fileName, HttpServletResponse response) {
        List<HlOtherCommodity> hlOtherCommodityList = excelService.excelObjectList(HlOtherCommodity.class, filePath, fileName, false);
        List<HlOtherCommodity> hlOtherCommodities = new ArrayList<>();
        for (int i = 0; i < hlOtherCommodityList.size(); i++) {
            HlOtherCommodity hlOtherCommodity = hlOtherCommodityList.get(i);
            if (ObjectUtils.isNotEmpty(hlOtherCommodity.getBandwidth())) {
                String[] split = hlOtherCommodity.getBandwidth().split("-");
                for (String s : split) {
                    HlOtherCommodity otherCommodity = new HlOtherCommodity();
                    otherCommodity.setCode(hlOtherCommodity.getCode());
                    otherCommodity.setMaterialMark(hlOtherCommodity.getMaterialMark());
                    otherCommodity.setTpType(hlOtherCommodity.getTpType());
                    otherCommodity.setBandwidth(s);
                    otherCommodity.setMerchantCode(hlOtherCommodity.getMerchantCode());
                    hlOtherCommodities.add(otherCommodity);
                }
            } else {
                hlOtherCommodities.add(hlOtherCommodity);
            }
        }
        hlOtherCommodityService.insertList(hlOtherCommodities);
        return AjaxResult.success();
    }

    /**
     * 米思米同步轮类型转换网站
     */
    @Override
    public AjaxResult miSiMiTypeConvertWebsite(String miSiMiTypeCommodity) {
        // 去除空格
        miSiMiTypeCommodity = miSiMiTypeCommodity.replace(" ", "");
        log.info("米思米商品编码 ==> {}", miSiMiTypeCommodity);

        if (!miSiMiTypeCommodity.contains("-")) {
            // AHTF20S3M100
            // 从左往右以第一个数字为节点开始截取字符串
            String[] split = miSiMiTypeCommodity.split("(?=\\d)", 2);
            miSiMiTypeCommodity = split[0] + split[1].substring(0, 2) + "-" + split[1].substring(2);
        }

        // 从左往右以第一个数字为节点开始截取字符串
        String[] split = miSiMiTypeCommodity.split("(?=\\d)", 2);
        String[] splitSplit = split[1].split("-");

        // HTPS60S3M100-A-H10-ZFC24.0-ZM4
        HlOtherCommodity replace = new HlOtherCommodity();
        replace.setCode(split[0]);
        replace.setMerchantCode("MiSiMi");
        if (miSiMiTypeCommodity.contains("H3M")) {
            replace.setBandwidth("H3M");
        } else if (miSiMiTypeCommodity.contains("H5M")) {
            replace.setBandwidth("H5M");
        } else if (miSiMiTypeCommodity.contains("H8M")) {
            replace.setBandwidth("H8M");
        } else if (miSiMiTypeCommodity.contains("S2M")) {
            replace.setBandwidth("S2M");
        } else if (miSiMiTypeCommodity.contains("S3M")) {
            replace.setBandwidth("S3M");
        } else if (miSiMiTypeCommodity.contains("S5M")) {
            replace.setBandwidth("S5M");
        } else if (miSiMiTypeCommodity.contains("S8M")) {
            replace.setBandwidth("S8M");
        } else if (miSiMiTypeCommodity.contains("T5100") || miSiMiTypeCommodity.contains("T5150") || miSiMiTypeCommodity.contains("T5200") || miSiMiTypeCommodity.contains("T5250")) {
            replace.setBandwidth("T5");
        } else if (miSiMiTypeCommodity.contains("T10150") || miSiMiTypeCommodity.contains("T10200") || miSiMiTypeCommodity.contains("T10250") || miSiMiTypeCommodity.contains("T10300") || miSiMiTypeCommodity.contains("T10400") || miSiMiTypeCommodity.contains("T10500")) {
            replace.setBandwidth("T10");
        } else if (miSiMiTypeCommodity.contains("MXL019") || miSiMiTypeCommodity.contains("MXL025") || miSiMiTypeCommodity.contains("MXL037") || miSiMiTypeCommodity.contains("MXL050")) {
            replace.setBandwidth("MXL");
        } else if (miSiMiTypeCommodity.contains("XL025") || miSiMiTypeCommodity.contains("XL031") || miSiMiTypeCommodity.contains("XL037") || miSiMiTypeCommodity.contains("XL050") || miSiMiTypeCommodity.contains("XL100")) {
            replace.setBandwidth("XL");
        } else if (miSiMiTypeCommodity.contains("L050") || miSiMiTypeCommodity.contains("L075") || miSiMiTypeCommodity.contains("L100") || miSiMiTypeCommodity.contains("L150")) {
            replace.setBandwidth("L");
        } else if (miSiMiTypeCommodity.contains("H075") || miSiMiTypeCommodity.contains("H100") || miSiMiTypeCommodity.contains("H150") || miSiMiTypeCommodity.contains("H200")) {
            replace.setBandwidth("H");
        }
        HlOtherCommodity hlOtherCommodity = hlOtherCommodityService.selectOne(replace);

        if (ObjectUtils.isEmpty(hlOtherCommodity)) {
            replace = new HlOtherCommodity();
            replace.setCode(split[0]);
            replace.setMerchantCode("MiSiMi");
            hlOtherCommodity = hlOtherCommodityService.selectOne(replace);
        }

        if (ObjectUtils.isNotEmpty(hlOtherCommodity)) {
            StringBuilder commodity = new StringBuilder(hlOtherCommodity.getTpType() + hlOtherCommodity.getMaterialMark());

            ResultTimingPulleyPrice resultTimingPulleyPrice = new ResultTimingPulleyPrice();
            if ("TP".equals(hlOtherCommodity.getTpType())) {
                // HTPA25S5M300-A-Y13-Q19-R19-S10-T10

                String teethNum = splitSplit[0].substring(0, 2);
                String toothBandwidth = splitSplit[0].substring(2);
                String shape = splitSplit[1];
                String tpAxleHoleType = splitSplit[2].substring(0, 1);

                commodity.append("-").append(toothBandwidth).append("-").append(teethNum).append("-").append(shape).append("-").append(tpAxleHoleType).append("-d").append(splitSplit[2].substring(1));

                if (splitSplit.length > 3) {
                    for (int i = 0; i < splitSplit.length; i++) {
                        if (i > 2) {
                            commodity.append("-").append(splitSplit[i]);
                        }
                    }
                }
            }
            else if ("IG".equals(hlOtherCommodity.getTpType())) {

                // AHTFW28-S8M250-15
                // IGH-H150-16-W-6002

                // AHTF28S5M100
                // AHTF20S5M100-FC32
                if (splitSplit.length < 3) {
                    boolean isNumber = splitSplit[0].matches("\\d+");
                    if (isNumber) {
                        String str = splitSplit[0] + splitSplit[1];
                        String numberPart1 = "";
                        String numberPart2 = "";

                        for (int i = 0; i < str.length(); i++) {
                            char c = str.charAt(i);
                            if (Character.isLetter(c)) {
                                numberPart1 = str.substring(0, i);
                                numberPart2 = str.substring(i);
                                break;
                            }
                        }
                        String[] updatedSplit = new String[splitSplit.length];
                        updatedSplit[0] = numberPart1;
                        updatedSplit[1] = numberPart2;
                        splitSplit = updatedSplit;
                    } else {
                        String str = splitSplit[0];
                        String numberPart1 = "";
                        String numberPart2 = "";

                        for (int i = 0; i < str.length(); i++) {
                            char c = str.charAt(i);
                            if (Character.isLetter(c)) {
                                numberPart1 = str.substring(0, i);
                                numberPart2 = str.substring(i);
                                break;
                            }
                        }
                        String[] updatedSplit = new String[splitSplit.length + 1];
                        updatedSplit[0] = numberPart1;
                        updatedSplit[1] = numberPart2;
                        updatedSplit[2] = splitSplit[1];
                        splitSplit = updatedSplit;
                    }
                }

                HlOtherCommodityDetails otherCommodityDetails = new HlOtherCommodityDetails();
                otherCommodityDetails.setCode(split[0]);
                otherCommodityDetails.setTeeth(splitSplit[0]);
                otherCommodityDetails.setBandwidth(splitSplit[1]);
                if (splitSplit.length >= 3 && splitSplit[2].matches("[0-9]+")) {
                    otherCommodityDetails.setShaftDiameter(splitSplit[2]);
                }
                HlOtherCommodityDetails hlOtherCommodityDetails = hlOtherCommodityDetailsService.selectOne(otherCommodityDetails, "IG");

                String one = splitSplit[0];
                String two = splitSplit[1];

                splitSplit[0] = two;
                splitSplit[1] = one;

                commodity.append("-").append(splitSplit[0]).append("-").append(splitSplit[1]);

                if (ObjectUtils.isNotEmpty(hlOtherCommodityDetails)) {
                    commodity.append("-").append(hlOtherCommodityDetails.getBearingLayout()).append("-").append(hlOtherCommodityDetails.getBearingType());
                }

                if (splitSplit.length > 3) {
                    for (int i = 0; i < splitSplit.length; i++) {
                        if (i > 2) {
                            commodity.append("-").append(splitSplit[i]);
                        }
                    }
                } else if (splitSplit.length == 3) {
                    boolean isNumber = splitSplit[2].matches("\\d+");
                    if (!isNumber) {
                        commodity.append("-").append(splitSplit[2]);
                    }
                }
            }
            else if ("PL".equals(hlOtherCommodity.getTpType())) {
                // HTLA34S8M400-F-35

                String teethNum = splitSplit[0].substring(0, 2);
                String toothBandwidth = splitSplit[0].substring(2);

                commodity.append("-").append(toothBandwidth).append("-").append(teethNum).append("-").append(splitSplit[1])
                        .append("-").append(hlOtherCommodity.getBandwidth()).append("-d").append(splitSplit[2]);

            }
            else if (hlOtherCommodity.getTpType().contains("TG")) {

                // HBGA20-6-FC21 = TGTH-D20-T6-A-625-t1-FC21


                HlOtherCommodityDetails otherCommodityDetails = new HlOtherCommodityDetails();
                otherCommodityDetails.setCode(split[0]);
                otherCommodityDetails.setTeeth(splitSplit[0]);
                otherCommodityDetails.setShaftDiameter(splitSplit[1]);
                HlOtherCommodityDetails hlOtherCommodityDetails = hlOtherCommodityDetailsService.selectOne(otherCommodityDetails, "TG");

                BigDecimal L = new BigDecimal(0);
                if (ObjectUtils.isNotEmpty(hlOtherCommodityDetails.getBandwidth())) {
                    L = new BigDecimal(hlOtherCommodityDetails.getBandwidth());
                }

                // 注意TGU 的 W 的 D 很特殊
                if (split[0].contains("HBG")) {
                    commodity.append("-D").append(splitSplit[0]).append("-T").append(splitSplit[1]);

                } else {
                    if ("TGU".equals(hlOtherCommodity.getTpType())) {
                        commodity.append("-W").append(splitSplit[0]).append("-D").append(splitSplit[1]);
                    } else {
                        commodity.append("-D").append(splitSplit[0]).append("-T").append(splitSplit[1]);
                    }
                }

                if (ObjectUtils.isNotEmpty(hlOtherCommodityDetails)) {
                    commodity.append("-").append(hlOtherCommodityDetails.getBearingLayout()).append("-").append(hlOtherCommodityDetails.getBearingType());
                }

                if ("TGT".equals(hlOtherCommodity.getTpType())) {
                    commodity.append("-t").append(L);
                } else if ("TGR".equals(hlOtherCommodity.getTpType())) {
                    commodity.append("-r").append(L);
                }

                for (int i = 2; i < splitSplit.length; i++) {
                    commodity.append("-").append(splitSplit[i]);
                }
            }
            else if ("ETP".equals(hlOtherCommodity.getTpType())) {
                // HTCPA40-S5M100-19 = ETPH-S5M100-40-d19
                commodity.append("-").append(splitSplit[1]).append("-").append(splitSplit[0]).append("-d").append(splitSplit[2]);
            }
            log.info("转换后的商品编码 ==> {}", commodity.toString());
            return AjaxResult.success("操作成功", typeSpecialCharacter(commodity.toString()));
        } else {
            return AjaxResult.error("未查到具体型号");
        }
    }

    /**
     * 米思米带齿惰轮导入数据库
     */
    @Override
    public AjaxResult miSiMiIg(String filePath, String fileName, HttpServletResponse response) {
        List<HlOtherCommodityDetails> hlOtherCommodityDetailsList = excelService.excelObjectList(HlOtherCommodityDetails.class, filePath, fileName, false);

        List<HlOtherCommodityDetails> hlOtherCommodityDetailsArrayList = new ArrayList<>();

        for (int i = 0; i < hlOtherCommodityDetailsList.size(); i++) {
            HlOtherCommodityDetails hlOtherCommodityDetails = hlOtherCommodityDetailsList.get(i);
            String code = hlOtherCommodityDetails.getCode();
            String bearingLayout = hlOtherCommodityDetails.getBearingLayout();
            String bearingType = hlOtherCommodityDetails.getBearingType();
            String teeth = hlOtherCommodityDetails.getTeeth();
            String bandwidth = hlOtherCommodityDetails.getBandwidth();
            String shaftDiameter = hlOtherCommodityDetails.getShaftDiameter();
            String merchantCode = hlOtherCommodityDetails.getMerchantCode();

            String[] codeSplit = code.split("-");
            String[] bearingLayoutSplit = bearingLayout.split("-");
            String[] bearingTypeSplit = bearingType.split("-");
            String[] bandwidthSplit = bandwidth.split("-");

            HlOtherCommodityDetails otherCommodityDetails;
            for (String codeReplace : codeSplit) {
                if (bandwidthSplit.length > 1) {
                    A: for (int ii = 0; ii < bandwidthSplit.length; ii++) {
                        if (bearingTypeSplit.length > 1) {
                            if (bearingLayoutSplit.length > 1) {
                                otherCommodityDetails = new HlOtherCommodityDetails();
                                otherCommodityDetails.setCode(codeReplace);
                                otherCommodityDetails.setTeeth(teeth);
                                otherCommodityDetails.setBandwidth(bandwidthSplit[ii]);
                                otherCommodityDetails.setBearingType(bearingTypeSplit[ii]);
                                otherCommodityDetails.setBearingLayout(bearingLayoutSplit[ii]);
                                otherCommodityDetails.setShaftDiameter(shaftDiameter);
                                otherCommodityDetails.setMerchantCode(merchantCode);
                                hlOtherCommodityDetailsArrayList.add(otherCommodityDetails);
                            } else {
                                otherCommodityDetails = new HlOtherCommodityDetails();
                                otherCommodityDetails.setCode(codeReplace);
                                otherCommodityDetails.setTeeth(teeth);
                                otherCommodityDetails.setBandwidth(bandwidthSplit[ii]);
                                otherCommodityDetails.setBearingType(bearingTypeSplit[ii]);
                                otherCommodityDetails.setBearingLayout(bearingLayout);
                                otherCommodityDetails.setShaftDiameter(shaftDiameter);
                                otherCommodityDetails.setMerchantCode(merchantCode);
                                hlOtherCommodityDetailsArrayList.add(otherCommodityDetails);
                            }
                        } else {
                            otherCommodityDetails = new HlOtherCommodityDetails();
                            otherCommodityDetails.setCode(codeReplace);
                            otherCommodityDetails.setTeeth(teeth);
                            otherCommodityDetails.setBandwidth(bandwidthSplit[ii]);
                            otherCommodityDetails.setBearingType(bearingType);
                            otherCommodityDetails.setBearingLayout(bearingLayout);
                            otherCommodityDetails.setShaftDiameter(shaftDiameter);
                            otherCommodityDetails.setMerchantCode(merchantCode);
                            hlOtherCommodityDetailsArrayList.add(otherCommodityDetails);
                        }
                    }
                } else {
                    otherCommodityDetails = new HlOtherCommodityDetails();
                    otherCommodityDetails.setCode(codeReplace);
                    otherCommodityDetails.setTeeth(teeth);
                    otherCommodityDetails.setBandwidth(bandwidth);
                    otherCommodityDetails.setBearingType(bearingType);
                    otherCommodityDetails.setBearingLayout(bearingLayout);
                    otherCommodityDetails.setShaftDiameter(shaftDiameter);
                    otherCommodityDetails.setMerchantCode(merchantCode);
                    hlOtherCommodityDetailsArrayList.add(otherCommodityDetails);
                }
            }
        }
        hlOtherCommodityDetailsService.insertList(hlOtherCommodityDetailsArrayList);
        // log.info("数据 ==> {}", JSON.toJSONString(hlOtherCommodityDetailsArrayList));
        return AjaxResult.success();
    }

    /**
     * 米思米同步轮类型转换
     */
    @Override
    public String miSiMiTypeConvert(String filePath, String fileName, HttpServletResponse response) throws Exception {

        List<ResultConvert> convertList = excelService.excelObjectList(ResultConvert.class, filePath, fileName, false);

        List<ResultConvert> resultConvertList = new ArrayList<>();

        for (int i = 0; i < convertList.size(); i++) {
            ResultConvert convert = convertList.get(i);
            String otherCommodity = convert.getOtherCommodity();
            log.info("米思米商品编码 ==> {}", otherCommodity);

            // 从左往右以第一个数字为节点开始截取字符串
            String[] split = otherCommodity.split("(?=\\d)", 2);
            HlOtherCommodity replace = new HlOtherCommodity();
            replace.setCode(split[0]);
            if (split[1].contains("MXL")) {
                replace.setBandwidth("XL-MXL");
            } else if (split[1].contains("XL")) {
                replace.setBandwidth("XL-MXL");
            } else if (split[1].contains("L")) {
                replace.setBandwidth("L-H");
            } else if (split[1].contains("H")) {
                replace.setBandwidth("L-H");
            }
            HlOtherCommodity hlOtherCommodity = hlOtherCommodityService.selectOne(replace);

            if (ObjectUtils.isNotEmpty(hlOtherCommodity)) {
                StringBuilder commodity = new StringBuilder(hlOtherCommodity.getTpType() + hlOtherCommodity.getMaterialMark());

                ResultTimingPulleyPrice resultTimingPulleyPrice = new ResultTimingPulleyPrice();

                String[] splitSplit = split[1].split("-");

                if ("TP".equals(hlOtherCommodity.getTpType())) {
                    String teethNum = splitSplit[0].substring(0, 2);
                    String toothBandwidth = splitSplit[0].substring(2);
                    String shape = splitSplit[1];
                    String tpAxleHoleType = splitSplit[2].substring(0, 1);

                    commodity.append("-").append(toothBandwidth).append("-").append(teethNum).append("-").append(shape).append("-").append(tpAxleHoleType).append("-d").append(splitSplit[2].substring(1));

                    log.info("转换后的商品编码 ==> {}", commodity.toString());
                    AjaxResult ajaxResult = tpCostPrice(commodity.toString(), null, null, false, false, "13711851155");
                    resultTimingPulleyPrice = (ResultTimingPulleyPrice) ajaxResult.get("data");
                } else if ("IG".equals(hlOtherCommodity.getTpType())) {

                    // AHTFW28-S8M250-15
                    // IGH-H150-16-W-6002

                    HlOtherCommodityDetails otherCommodityDetails = new HlOtherCommodityDetails();
                    otherCommodityDetails.setCode(split[0]);
                    otherCommodityDetails.setTeeth(splitSplit[0]);
                    otherCommodityDetails.setBandwidth(splitSplit[1]);
                    if (splitSplit.length >= 3) {
                        otherCommodityDetails.setShaftDiameter(splitSplit[2]);
                    }
                    HlOtherCommodityDetails hlOtherCommodityDetails = hlOtherCommodityDetailsService.selectOne(otherCommodityDetails, "IG");

                    String one = splitSplit[0];
                    String two = splitSplit[1];

                    splitSplit[0] = two;
                    splitSplit[1] = one;

                    commodity.append("-").append(splitSplit[0]).append("-").append(splitSplit[1]);

                    if (ObjectUtils.isNotEmpty(hlOtherCommodityDetails)) {
                        commodity.append("-").append(hlOtherCommodityDetails.getBearingLayout()).append("-").append(hlOtherCommodityDetails.getBearingType());
                    }

                    if (splitSplit.length > 3) {
                        for (int ii = 0; ii < splitSplit.length; ii++) {
                            if (ii > 2) {
                                commodity.append("-").append(splitSplit[ii]);
                            }
                        }
                    }
                    log.info("转换后的商品编码 ==> {}", commodity.toString());
                    AjaxResult ajaxResult = igCostPrice(commodity.toString(), null, null, false, false, "13711851155");
                    resultTimingPulleyPrice = (ResultTimingPulleyPrice) ajaxResult.get("data");
                }

                String num = convert.getNum();
                convertList.get(i).setNum(num);
                convertList.get(i).setCommodity(commodity.toString());

                if (ObjectUtils.isNotEmpty(resultTimingPulleyPrice)) {
                    BigDecimal bigDecimal = new BigDecimal(num);
                    if (bigDecimal.compareTo(BigDecimal.valueOf(10)) < 0) {
                        convertList.get(i).setPrice(resultTimingPulleyPrice.getTaxNum1());
                    }
                    if (bigDecimal.compareTo(BigDecimal.valueOf(20)) < 0) {
                        convertList.get(i).setPrice(resultTimingPulleyPrice.getTaxNum10());
                    }
                    if (bigDecimal.compareTo(BigDecimal.valueOf(50)) < 0) {
                        convertList.get(i).setPrice(resultTimingPulleyPrice.getTaxNum20());
                    }
                }
            }
        }
        return excelService.wired(convertList, ResultConvert.class, "excelName", response);
    }

    /**
     * 爱安特同步轮类型转换网站
     */
    @Override
    public AjaxResult aiAnTeTypeConvert(String aiAnTeTypeCommodity) {

        // 去除空格
        aiAnTeTypeCommodity = aiAnTeTypeCommodity.replace(" ", "");
        log.info("爱安特商品编码 ==> {}", aiAnTeTypeCommodity);

        boolean fb = false;
        if ("FB-".equals(aiAnTeTypeCommodity.substring(0, 3))) {
            fb = true;
            aiAnTeTypeCommodity = aiAnTeTypeCommodity.substring(3);
        }

        String[] split = aiAnTeTypeCommodity.split("-");
        HlOtherCommodity replace = new HlOtherCommodity();
        replace.setCode(split[0]);
        replace.setMerchantCode("AiAnTe");
        HlOtherCommodity hlOtherCommodity = hlOtherCommodityService.selectOne(replace);

        if (ObjectUtils.isNotEmpty(hlOtherCommodity)) {
            StringBuilder commodity = new StringBuilder(hlOtherCommodity.getTpType() + hlOtherCommodity.getMaterialMark());

            if ("TP".equals(hlOtherCommodity.getTpType())) {
                String teethNum = split[2];
                String toothBandwidth = split[1];
                String shape = split[3];
                String tpAxleHoleType = split[4].substring(0, 1);

                commodity.append("-").append(toothBandwidth).append("-").append(teethNum).append("-").append(shape).append("-").append(tpAxleHoleType).append("-d").append(split[4].substring(1));

                if (split.length > 5) {
                    for (int i = 0; i < split.length; i++) {
                        if (i > 4) {
                            commodity.append("-").append(split[i]);
                        }
                    }
                }
            } else if ("IG".equals(hlOtherCommodity.getTpType())) {

                // ADDAA-S5M250-36-d15
                // IGH-H150-16-W-6002

                HlOtherCommodityDetails otherCommodityDetails = new HlOtherCommodityDetails();
                otherCommodityDetails.setCode(split[0]);
                otherCommodityDetails.setTeeth(split[2]);
                otherCommodityDetails.setBandwidth(split[1]);
                otherCommodityDetails.setShaftDiameter(split[3].substring(1));
                HlOtherCommodityDetails hlOtherCommodityDetails = hlOtherCommodityDetailsService.selectOne(otherCommodityDetails, "IG");

                commodity.append("-").append(split[1]).append("-").append(split[2]);

                if (ObjectUtils.isNotEmpty(hlOtherCommodityDetails)) {
                    commodity.append("-").append(hlOtherCommodityDetails.getBearingLayout()).append("-").append(hlOtherCommodityDetails.getBearingType());
                }

                if (split.length > 4) {
                    for (int i = 0; i < split.length; i++) {
                        if (i > 3) {
                            commodity.append("-").append(split[i]);
                        }
                    }
                }

            } else if ("PL".equals(hlOtherCommodity.getTpType())) {
                // APZAA-T5100-22-E-d8

                commodity.append("-").append(split[1]).append("-").append(split[2])
                        .append("-").append(split[3]).append("-").append(hlOtherCommodity.getBandwidth()).append("-").append(split[4]);
            }
            if (fb) {
                commodity.insert(0, "FB-");
            }
            log.info("转换后的商品编码 ==> {}", commodity.toString());
            return AjaxResult.success("操作成功", typeSpecialCharacter(commodity.toString()));
        } else {
            return AjaxResult.error("未查到具体型号");
        }
    }

    /**
     * 上隆同步轮类型转换网站
     */
    @Override
    public AjaxResult shangLongTypeConvert(String shangLongTypeCommodity) {
        // 去除空格
        shangLongTypeCommodity = shangLongTypeCommodity.replace(" ", "");
        log.info("上隆商品编码 ==> {}", shangLongTypeCommodity);

        String[] split = shangLongTypeCommodity.split("-");
        String code = "";


        HlOtherCommodity replace = new HlOtherCommodity();
        boolean h = false;
        if (split[0].contains("LGA")) {
            code = split[0];
            replace.setCode(code);
        } else {
            if ("LA3M".equals(split[0]) || "LA5M".equals(split[0]) || "LA8M".equals(split[0])) {
                h = true;
                code = split[0].substring(0, split[0].length() - 2);
            }
            else {
                code = split[0].substring(0, split[0].length() - 3);
            }
            replace.setCode(code);
        }
        replace.setMerchantCode("ShangLong");
        HlOtherCommodity hlOtherCommodity = hlOtherCommodityService.selectOne(replace);

        if (ObjectUtils.isNotEmpty(hlOtherCommodity)) {
            StringBuilder commodity = new StringBuilder(hlOtherCommodity.getTpType() + hlOtherCommodity.getMaterialMark());

            if ("TP".equals(hlOtherCommodity.getTpType())) {
                // TAAS2M-15-060-H3

                String teethNum = split[1];
                String toothBandwidth = split[0].substring(split[0].length() - 3) + split[2];
                String shape = code.substring(code.length() - 1);
                String tpAxleHoleType = split[3].substring(0, 1);

                commodity.append("-").append(toothBandwidth).append("-").append(teethNum).append("-").append(shape).append("-").append(tpAxleHoleType).append("-d").append(split[3].substring(1));
            } else if ("IG".equals(hlOtherCommodity.getTpType())) {
                // LAS3M-20-060
                // LA3M-44-150

                HlOtherCommodityDetails otherCommodityDetails = new HlOtherCommodityDetails();
                otherCommodityDetails.setCode(code);
                String toothBandwidth = "";
                otherCommodityDetails.setTeeth(split[1]);
                if (h) {
                    toothBandwidth = "H" + split[0].substring(split[0].length() - 2) + split[2];
                } else {
                    toothBandwidth = split[0].substring(split[0].length() - 3) + split[2];
                }
                otherCommodityDetails.setBandwidth(toothBandwidth);
                HlOtherCommodityDetails hlOtherCommodityDetails = hlOtherCommodityDetailsService.selectOne(otherCommodityDetails, "IG");

                commodity.append("-").append(toothBandwidth).append("-").append(split[1]);

                if (ObjectUtils.isNotEmpty(hlOtherCommodityDetails)) {
                    commodity.append("-").append(hlOtherCommodityDetails.getBearingLayout()).append("-").append(hlOtherCommodityDetails.getBearingType());
                }
            } else if ("PL".equals(hlOtherCommodity.getTpType())) {
                // TAES5M-24-150-D7
                // PLH-T5100-22-E-C-d8

                String teethNum = split[1];
                String toothBandwidth = split[0].substring(split[0].length() - 3) + split[2];
                String shape = code.substring(code.length() - 1);

                commodity.append("-").append(toothBandwidth).append("-").append(teethNum).append("-").append(shape)
                        .append("-").append(hlOtherCommodity.getBandwidth()).append("-d").append(split[3].substring(1));
            }
            else if (hlOtherCommodity.getTpType().contains("TG")) {
                // LGAF-W27-D60
                // TGUH-D60-W27-B-6201

                HlOtherCommodityDetails otherCommodityDetails = new HlOtherCommodityDetails();
                otherCommodityDetails.setCode(split[0]);
                otherCommodityDetails.setTeeth(split[1].substring(1));
                otherCommodityDetails.setShaftDiameter(split[2].substring(1));
                HlOtherCommodityDetails hlOtherCommodityDetails = hlOtherCommodityDetailsService.selectOne(otherCommodityDetails, "TG");

                commodity.append("-").append(split[2]).append("-").append(split[1]);
                if (ObjectUtils.isNotEmpty(hlOtherCommodityDetails)) {
                    commodity.append("-").append(hlOtherCommodityDetails.getBearingLayout()).append("-").append(hlOtherCommodityDetails.getBearingType());
                }
            }
            log.info("转换后的商品编码 ==> {}", commodity.toString());
            return AjaxResult.success("操作成功", typeSpecialCharacter(commodity.toString()));
        } else {
            return AjaxResult.error("未查到具体型号");
        }
    }

    /**
     * 三益同步轮类型转换网站
     */
    @Override
    public AjaxResult sanYiTypeConvert(String sanYiTypeCommodity) {
        // 去除空格
        sanYiTypeCommodity = sanYiTypeCommodity.replace(" ", "");
        log.info("三益商品编码 ==> {}", sanYiTypeCommodity);

        String[] split = sanYiTypeCommodity.split("-");
        String code = "";

        if ("E".equals(split[0]) || "C".equals(split[0])) {
            // E-TPCB22S5M250-A-N15

            // TPCB22S5M250-A-N15
            split = sanYiTypeCommodity.substring(2).split("(?=\\d)", 2);
        } else {
            // TPCB22S5M250-A-N15
            split = sanYiTypeCommodity.split("(?=\\d)", 2);
        }
        String[] splitSplit = split[1].split("-");

        HlOtherCommodity replace = new HlOtherCommodity();
        replace.setCode(split[0]);
        replace.setMerchantCode("SanYi");
        HlOtherCommodity hlOtherCommodity = hlOtherCommodityService.selectOne(replace);

        if (ObjectUtils.isNotEmpty(hlOtherCommodity)) {
            StringBuilder commodity = new StringBuilder(hlOtherCommodity.getTpType() + hlOtherCommodity.getMaterialMark());
            ResultTimingPulleyPrice resultTimingPulleyPrice = new ResultTimingPulleyPrice();

            if ("TP".equals(hlOtherCommodity.getTpType())) {
                // TPCB22S5M250-A-N15

                String teethNum = splitSplit[0].substring(0, 2);
                String toothBandwidth = splitSplit[0].substring(2);
                String shape = splitSplit[1];
                String tpAxleHoleType = splitSplit[2].substring(0, 1);

                commodity.append("-").append(toothBandwidth).append("-").append(teethNum).append("-").append(shape).append("-").append(tpAxleHoleType).append("-d").append(splitSplit[2].substring(1));

                if (splitSplit.length > 3) {
                    for (int i = 0; i < splitSplit.length; i++) {
                        if (i > 2) {
                            commodity.append("-").append(splitSplit[i]);
                        }
                    }
                }
            }
            else if ("IG".equals(hlOtherCommodity.getTpType())) {
                String teethNum = splitSplit[0].substring(0, 2);
                String toothBandwidth = splitSplit[0].substring(2);

                // FTAC16S5M100-FA27
                // FTACW18S5M150-8-FA28.5
                HlOtherCommodityDetails otherCommodityDetails = new HlOtherCommodityDetails();
                otherCommodityDetails.setCode(split[0]);
                otherCommodityDetails.setTeeth(teethNum);
                otherCommodityDetails.setBandwidth(toothBandwidth);
                // 16S5M100
                if (splitSplit.length > 1) {
                    if (splitSplit[1].matches("[0-9]+")) {
                        otherCommodityDetails.setShaftDiameter(splitSplit[1]);
                    }
                }
                HlOtherCommodityDetails hlOtherCommodityDetails = hlOtherCommodityDetailsService.selectOne(otherCommodityDetails, "IG");

                commodity.append("-").append(toothBandwidth).append("-").append(teethNum);

                if (ObjectUtils.isNotEmpty(hlOtherCommodityDetails)) {
                    commodity.append("-").append(hlOtherCommodityDetails.getBearingLayout()).append("-").append(hlOtherCommodityDetails.getBearingType());
                }

                if (splitSplit.length > 1) {
                    for (int i = 1; i < splitSplit.length; i++) {
                        if (i == 1 && splitSplit[1].matches("[0-9]+")) {
                            continue;
                        } else {
                            commodity.append("-").append(splitSplit[i]);
                        }
                    }
                }
            }
            else if ("PL".equals(hlOtherCommodity.getTpType())) {
                // KTPAC48S3M100-E-14
                // KTPAC28S5M100-E-8-FA45

                String teethNum = splitSplit[0].substring(0, 2);
                String toothBandwidth = splitSplit[0].substring(2);

                commodity.append("-").append(toothBandwidth).append("-").append(teethNum).append("-").append(splitSplit[1])
                        .append("-").append(hlOtherCommodity.getBandwidth()).append("-d").append(splitSplit[2]);

            }

            log.info("转换后的商品编码 ==> {}", commodity.toString());
            return AjaxResult.success("操作成功", typeSpecialCharacter(commodity.toString()));
        } else {
            return AjaxResult.error("未查到具体型号");
        }
    }

    /**
     * 陌生型号类型转换网站
     */
    @Override
    public AjaxResult strangeTypeConvertWebsite(String strangeTypeCommodity) {
        // 去除空格
        strangeTypeCommodity = strangeTypeCommodity.replace(" ", "");
        log.info("陌生型号类型转换网站 ==> {}", strangeTypeCommodity);
        // YiHeDa
        String yiHeDaTypeCommodity = strangeTypeCommodity;
        HlOtherCommodity hlOtherCommodity = new HlOtherCommodity();

        String[] yiHeDaSplitSplit = yiHeDaTypeCommodity.split("-");
        // 查询其他型号表
        HlOtherCommodity yiHeDaReplace = new HlOtherCommodity();
        yiHeDaReplace.setCode(yiHeDaSplitSplit[0]);
        yiHeDaReplace.setMerchantCode("YiHeDa");
        hlOtherCommodity = hlOtherCommodityService.selectOne(yiHeDaReplace);
        if (ObjectUtils.isEmpty(hlOtherCommodity)) {
            // MiSiMi
            String miSiMiTypeCommodity = strangeTypeCommodity;
            if (!miSiMiTypeCommodity.contains("-")) {
                // AHTF20S3M100
                // 从左往右以第一个数字为节点开始截取字符串
                String[] miSiMiSplit = miSiMiTypeCommodity.split("(?=\\d)", 2);
                miSiMiTypeCommodity = miSiMiSplit[0] + miSiMiSplit[1].substring(0, 2) + "-" + miSiMiSplit[1].substring(2);
            }
            // 从左往右以第一个数字为节点开始截取字符串
            String[] miSiMiSplit = miSiMiTypeCommodity.split("(?=\\d)", 2);
            String[] miSiMiSplitSplit = miSiMiSplit[1].split("-");
            // HTPS60S3M100-A-H10-ZFC24.0-ZM4
            HlOtherCommodity miSiMiReplace = new HlOtherCommodity();
            miSiMiReplace.setCode(miSiMiSplit[0]);
            miSiMiReplace.setMerchantCode("MiSiMi");
            List<HlOtherCommodity> hlOtherCommodities = hlOtherCommodityService.selectHlOtherCommodityList(miSiMiReplace);
            if (ObjectUtils.isEmpty(hlOtherCommodities)) {
                String aiAnTeTypeCommodity = strangeTypeCommodity;
                boolean fb = false;
                if ("FB-".equals(aiAnTeTypeCommodity.substring(0, 3))) {
                    fb = true;
                    aiAnTeTypeCommodity = aiAnTeTypeCommodity.substring(3);
                }
                String[] aiAnTeSplit = aiAnTeTypeCommodity.split("-");
                HlOtherCommodity aiAnTeReplace = new HlOtherCommodity();
                aiAnTeReplace.setCode(aiAnTeSplit[0]);
                aiAnTeReplace.setMerchantCode("AiAnTe");
                hlOtherCommodity = hlOtherCommodityService.selectOne(aiAnTeReplace);
                if (ObjectUtils.isEmpty(hlOtherCommodity)) {
                    String shangLongTypeCommodity = strangeTypeCommodity;
                    String[] shangLongSplit = shangLongTypeCommodity.split("-");
                    String shangLongCode = "";
                    HlOtherCommodity shangLongReplace = new HlOtherCommodity();
                    if (shangLongSplit[0].contains("LGA")) {
                        shangLongCode = shangLongSplit[0];
                        shangLongReplace.setCode(shangLongCode);
                    } else {
                        if ("LA3M".equals(shangLongSplit[0]) || "LA5M".equals(shangLongSplit[0]) || "LA8M".equals(shangLongSplit[0])) {
                            shangLongCode = shangLongSplit[0].substring(0, shangLongSplit[0].length() - 2);
                        }
                        else {
                            if (shangLongSplit[0].length() >= 3) {
                                shangLongCode = shangLongSplit[0].substring(0, shangLongSplit[0].length() - 3);
                            }
                        }
                        shangLongReplace.setCode(shangLongCode);
                    }
                    shangLongReplace.setMerchantCode("ShangLong");
                    hlOtherCommodity = hlOtherCommodityService.selectOne(shangLongReplace);
                    if (ObjectUtils.isEmpty(hlOtherCommodity)) {
                        String sanYiTypeCommodity = strangeTypeCommodity;
                        String[] sanYiSplit = sanYiTypeCommodity.split("-");
                        if ("E".equals(sanYiSplit[0]) || "C".equals(sanYiSplit[0])) {
                            sanYiSplit = sanYiTypeCommodity.substring(2).split("(?=\\d)", 2);
                        } else {
                            sanYiSplit = sanYiTypeCommodity.split("(?=\\d)", 2);
                        }
                        HlOtherCommodity sanYiReplace = new HlOtherCommodity();
                        sanYiReplace.setCode(sanYiSplit[0]);
                        sanYiReplace.setMerchantCode("SanYi");
                        hlOtherCommodity = hlOtherCommodityService.selectOne(sanYiReplace);
                        if (ObjectUtils.isEmpty(hlOtherCommodity)) {
                            return AjaxResult.error("未查到具体型号");
                        } else {
                            return sanYiTypeConvert(strangeTypeCommodity);
                        }
                    } else {
                        return shangLongTypeConvert(strangeTypeCommodity);
                    }
                } else {
                    return aiAnTeTypeConvert(strangeTypeCommodity);
                }
            } else {
                return miSiMiTypeConvertWebsite(strangeTypeCommodity);
            }
        } else {
            return yiHeDaTypeConvertWebsite(strangeTypeCommodity);
        }
    }

    /**
     * 型号转化特殊字符处理
     */
    public String typeSpecialCharacter(String typeSpecialCharacter) {
        if (typeSpecialCharacter.contains("FA")) {
            return typeSpecialCharacter.replace("FA", "FC");
        } else if (typeSpecialCharacter.contains("FT")) {
            return typeSpecialCharacter.replace("FT", "FC");
        } else {
            return typeSpecialCharacter;
        }
    }

    /**
     * 获取货期
     */
    @Override
    public AjaxResult getDeliveryTime(String deliveryTime) {


        return null;
    }

    /**
     * 根据同步轮商品编码获得同步轮信息
     * @param commodityCode 同步轮商品编码
     * @return 结果
     */
    public Map<String, String> communityInformationMap(String commodityCode) {
        HashMap<String, String> resultCommunityInformationMap = new HashMap<>();

        // 去除空格
        commodityCode = commodityCode.replace(" ", "");

        AjaxResult ajaxResult = null;
        ResultTimingPulleyPrice resultTimingPulleyPrice = null;

        // 正常 TPC-H5M250-50-A-N-d35
        // 非标 Z-TPH-S5MA32-50-B-N-d20-FC80.5
        // 非标 Z-TPH-S5MA32-25-A-Y-d13-Q19-R19-S10-T10-FC41
        // 非标 FB-TPH-T5100-18-A-H-d14
        // IGH-S5M150-24-W-608
        // PLC-S5M150-34-E-C-d14

        // 首先判定是否为 同步轮 还是 惰轮 还是 胀紧套
        log.info("商品型号编码 ==> {}", commodityCode);
        boolean oneTP = commodityCode.charAt(0) == 'T' && commodityCode.charAt(1) == 'P';
        boolean twoTP = commodityCode.contains("Z-") && commodityCode.charAt(2) == 'T' && commodityCode.charAt(3) == 'P';
        boolean threeTP = commodityCode.contains("FB-") && commodityCode.charAt(3) == 'T' && commodityCode.charAt(4) == 'P';

        boolean oneIG = commodityCode.charAt(0) == 'I' && commodityCode.charAt(1) == 'G';
        boolean onePL = commodityCode.charAt(0) == 'P' && commodityCode.charAt(1) == 'L';

        if (oneTP || threeTP) {
            if (threeTP) {
                commodityCode = commodityCode.substring(3);
            }
            ajaxResult = tpCostPrice(commodityCode, null, null, false, false, "13711851155");
            if ("200".equals(ajaxResult.get("code").toString())) {
                resultTimingPulleyPrice = (ResultTimingPulleyPrice) ajaxResult.get("data");
            } else {
                return null;
            }
        } else if (twoTP) {
            ajaxResult = tpCostPrice(commodityCode, null, null, false, true, "13711851155");
            if ("200".equals(ajaxResult.get("code").toString())) {
                resultTimingPulleyPrice = (ResultTimingPulleyPrice) ajaxResult.get("data");
            } else {
                return null;
            }
        } else if (oneIG) {
            // IGH-S5M150-24-W-608

            ajaxResult = igCostPrice(commodityCode, null, null, false, false, "13711851155");
            if ("200".equals(ajaxResult.get("code").toString())) {
                resultTimingPulleyPrice = (ResultTimingPulleyPrice) ajaxResult.get("data");
            } else {
                return null;
            }
        } else if (onePL) {
            // PLC-S5M150-34-E-C-d14

            String replacedString = commodityCode.replace("PL", "TP");
            String[] split = replacedString.split("-");
            split[3] = "A";
            split[4] = "H";
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < split.length; i++) {
                if (i == split.length - 1) {
                    stringBuilder.append(split[i]);
                } else {
                    stringBuilder.append(split[i]).append("-");
                }
            }
            ajaxResult = tpCostPrice(stringBuilder.toString(), null, null, false, false, "13711851155");
            if ("200".equals(ajaxResult.get("code").toString())) {
                resultTimingPulleyPrice = (ResultTimingPulleyPrice) ajaxResult.get("data");
            } else {
                return null;
            }
        } else {
            return null;
        }
        resultCommunityInformationMap.put("materialMark", resultTimingPulleyPrice.getMaterialMark());
        resultCommunityInformationMap.put("materialSize", resultTimingPulleyPrice.getMaterialSize());
        if (ObjectUtils.isEmpty(resultTimingPulleyPrice.getHlTimingPulley())) {
            return null;
        }
        resultCommunityInformationMap.put("tpF", resultTimingPulleyPrice.getHlTimingPulley().getTpF());
        if ("D".equals(resultTimingPulleyPrice.getTpShape())) {
            resultCommunityInformationMap.put("tpE", "0");
        } else {
            resultCommunityInformationMap.put("tpE", resultTimingPulleyPrice.getHlTimingPulley().getTpE());
        }

        // 对应Excel W 即 t
        BigDecimal tpT = new BigDecimal(resultTimingPulleyPrice.getHlTimingPulley().getTpT());
        tpT = tpT.setScale(1, RoundingMode.HALF_UP);

        resultCommunityInformationMap.put("tpT", tpT.toString());
        return resultCommunityInformationMap;
    }

    /**
     * 同步轮形状为 D 时，全部返回 O 价格
     */
    public ResultTimingPulleyPrice dTpShape() {
         ResultTimingPulleyPrice timingPulleyPrice = new ResultTimingPulleyPrice(
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                "0",
                null
        );
        return timingPulleyPrice;
    }

    /**
     * IG 带齿惰轮分割线
     * IG 带齿惰轮分割线
     * IG 带齿惰轮分割线
     */

    /**
     * IG 带齿惰轮成本和利润计算
     * IGH-S8M300-25-W-6201
     *
     * @param commodityCode 商品编码
     * @param consolePrinting 是否输出控制台打印日志
     * @param nonstandard 是否为非标
     * @return 结果
     */
    public AjaxResult igCostPrice(String commodityCode, BigDecimal bandwidthW, BigDecimal bandwidthL, Boolean consolePrinting, Boolean nonstandard, String authority) {

        String[] split = commodityCode.split("-");

        // IGH-T5150-20-W-698-FC32
        if (split.length <= 4 || commodityCode.matches(".*[\\u4e00-\\u9fa5].*")) {
            return AjaxResult.error("型号输入不正确");
        }

        String bearing = split[4];
        // 使用正则表达式判断字符串是否由数字组成
        if (!bearing.matches("\\d+")) {
            return AjaxResult.error("型号输入不正确");
        }

        // 查询 材质表 hl_material
        HlMaterial material = new HlMaterial();
        // 特殊材质
        if ("HK".equals(split[0].substring(split[0].length() - 2))) {
            material.setMaterialMark("HK");
        } else {
            material.setMaterialMark(split[0].substring(split[0].length() - 1));
        }
        HlMaterial hlMaterial = hlMaterialService.selectOne(material);
        if (ObjectUtils.isEmpty(hlMaterial)) {
            return AjaxResult.error("数据库中暂无：" + material.getMaterialMark() + "此材质");
        }

        // 查询 材质OD表 hl_material_od 的到现实具体有此直径的铝棒
        // 成品所需要的材料表 hl_material_Od
        String materialType = hlMaterial.getMaterialType();
        HlMaterialOd materialOd = new HlMaterialOd();
        materialOd.setMaterialType(materialType);
        List<HlMaterialOd> materialOdList = hlMaterialOdService.selectList(materialOd);

        // 齿形
        String tooth = split[1].substring(0, split[1].length() - 3);

        // 查询 齿距 hl_tooth
        HlTooth t = new HlTooth();
        t.setTooth(tooth);
        HlTooth hlTooth = hlToothService.selectOne(t);
        if (ObjectUtils.isEmpty(hlTooth)) {
            return AjaxResult.error("齿形数据异常，请联系管理员");
        }

        // 带齿惰轮代表的型号 IG
        String tp = split[0].substring(0, 2);
        // 带齿惰轮轴承布局
        String tpShape = split[3];
        // 带宽 永远是后三位
        String bandwidth = split[1].substring(split[1].length() - 3);
        // 齿数
        BigDecimal teethNum = new BigDecimal(split[2]);
        // 齿形带宽
        String toothBandwidth = split[1];

        // 查询 带宽表 hl_bandwidth
        // 以此获得 bandwidth_a 、 bandwidth_w 、 bandwidth_l 信息
        HlBandwidth bd = new HlBandwidth();
        bd.setBandwidth(toothBandwidth);
        List<HlBandwidth> hlBandwidths = hlBandwidthService.selectHlBandwidthList(bd);

        HlBandwidth hlBandwidth = resultHlBandwidth(teethNum, hlBandwidths);
        if (ObjectUtils.isEmpty(hlBandwidth)) {
            return AjaxResult.error("齿形带宽数据异常，请联系管理员");
        }

        // 同步轮材质
        String materialMark = material.getMaterialMark();

        // 查询商品的详细信息 hl_timing_pulley 同步轮表
        HlTimingPulley timingPulley = new HlTimingPulley();
        timingPulley.setTpType(tp);
        timingPulley.setTpMaterial(materialMark);
        timingPulley.setTpToothBandwidth(toothBandwidth);
        timingPulley.setTpTeethNum(split[2]);
        timingPulley.setTpShape(tpShape);
        HlTimingPulley hlTimingPulley = this.selectOne(timingPulley);
        if (ObjectUtils.isEmpty(hlTimingPulley)) {
            return AjaxResult.error("同步轮数据库暂无此型号，请联系管理员");
        }

        // 带齿惰轮成品的信息:   O.D.    重量    材料尺寸
        Map<String, String> resultIgFinishedProductInformationMap = resultIgFinishedProductInformationMap(teethNum, hlTooth, hlTimingPulley,
                materialOdList, hlBandwidth, hlMaterial, consolePrinting);
        // 带齿惰轮成品的信息:   O.D.
        BigDecimal OD = new BigDecimal(resultIgFinishedProductInformationMap.get("O.D."));
        // 带齿惰轮材料尺寸
        String materialSize = resultIgFinishedProductInformationMap.get("materialSize");
        // 带齿惰轮材料重量
        BigDecimal materialMass = new BigDecimal(resultIgFinishedProductInformationMap.get("materialMass"));
        // 带齿惰轮材料费用
        BigDecimal materialPrice = new BigDecimal(resultIgFinishedProductInformationMap.get("materialPrice"));
        // 带齿惰轮材料切断
        BigDecimal materialCutOff = resultMaterialCutOff(materialSize, materialPrice);
        // 车A时间
        BigDecimal vehicleATime = resultIgVehicleATime(materialSize, OD, hlBandwidth,
                hlTimingPulley, materialMark);
        // 车B时间
        BigDecimal vehicleBTime = resultIgVehicleBTime(materialSize, OD, hlBandwidth,
                hlTimingPulley, materialMark);
        // 车床费用
        BigDecimal latheCost = resultLatheCost(vehicleATime, vehicleBTime);
        // 滚齿时间
        BigDecimal hobbingTime = resultHobbingTime(hlMaterial, teethNum, hlBandwidth);
        // 滚齿费用
        BigDecimal hobbingCost = resultHobbingCost(tooth, teethNum, hobbingTime);
        // 压挡圈时间
        BigDecimal pressureRetainingRingTime = resultPressureRetainingRingTime();
        // 压挡圈费用
        BigDecimal pressureRetainingRingCost = resultPressureRetainingRingCost(pressureRetainingRingTime);
        // 带齿惰轮成品的信息:   重量
        BigDecimal finishedMass = new BigDecimal(resultIgFinishedProductInformationMap.get("finishedMass"));
        // 表面处理费用
        BigDecimal surfaceTreatmentCost = resultSurfaceTreatmentCost(hlMaterial, finishedMass);
        // 挡圈费用
        BigDecimal flangeCost = resultFlangeCost(materialMark, tooth, hlTimingPulley, tpShape);
        // 轴承费用
        BigDecimal bearingCost = resultBearingCost(tpShape, bearing);
        // 装配费用
        BigDecimal assembleCost = resultAssembleCost();
        // 包装费用
        BigDecimal packageCost = resultPackageCost(OD);
        // 物流费用
        BigDecimal logisticsCost = resultLogisticsCost(finishedMass);
        // 改孔时间
        BigDecimal holeModificationTime = resultIgHoleModificationTime(hlTimingPulley, OD,
                hlBandwidth, materialMark);
        // 改孔费用
        BigDecimal holeModificationCost = resultIgHoleModificationCost(holeModificationTime);

        // 额外成本
        BigDecimal additionalCost = resultAdditionalCost(hlTimingPulley, materialMark, bearingCost, tpShape);

        // 成本
        HashMap<String, BigDecimal> resultCostMap = resultIgCostMap(tpShape, materialPrice, materialCutOff,
                flangeCost, bearingCost, surfaceTreatmentCost, logisticsCost, latheCost, hobbingCost,
                pressureRetainingRingCost, packageCost, holeModificationCost, additionalCost, assembleCost);

        String materialsPartsCost = resultCostMap.get("materialsPartsCost").setScale(2, RoundingMode.HALF_UP).toString();
        String processCost = resultCostMap.get("processCost").setScale(2, RoundingMode.HALF_UP).toString();
        String assessCost = resultCostMap.get("assessCost").setScale(2, RoundingMode.HALF_UP).toString();
        String retailPrice = resultCostMap.get("retailPrice").setScale(2, RoundingMode.HALF_UP).toString();
        String taxRetailPrice = resultCostMap.get("taxRetailPrice").setScale(2, RoundingMode.HALF_UP).toString();

        String num1 = resultCostMap.get("num1").setScale(2, RoundingMode.HALF_UP).toString();
        String num2 = resultCostMap.get("num2").setScale(2, RoundingMode.HALF_UP).toString();
        String num3 = resultCostMap.get("num3").setScale(2, RoundingMode.HALF_UP).toString();
        String num4 = resultCostMap.get("num4").setScale(2, RoundingMode.HALF_UP).toString();
        String num5 = resultCostMap.get("num5").setScale(2, RoundingMode.HALF_UP).toString();
        String num10 = resultCostMap.get("num10").setScale(2, RoundingMode.HALF_UP).toString();
        String num20 = resultCostMap.get("num20").setScale(2, RoundingMode.HALF_UP).toString();
        String num50 = resultCostMap.get("num50").setScale(2, RoundingMode.HALF_UP).toString();
        String num100 = resultCostMap.get("num100").setScale(2, RoundingMode.HALF_UP).toString();
        String num500 = resultCostMap.get("num500").setScale(2, RoundingMode.HALF_UP).toString();
        String num1000 = resultCostMap.get("num1000").setScale(2, RoundingMode.HALF_UP).toString();
        String num3000 = resultCostMap.get("num3000").setScale(2, RoundingMode.HALF_UP).toString();

        String taxNum1 = resultCostMap.get("taxNum1").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum2 = resultCostMap.get("taxNum2").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum3 = resultCostMap.get("taxNum3").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum4 = resultCostMap.get("taxNum4").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum5 = resultCostMap.get("taxNum5").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum10 = resultCostMap.get("taxNum10").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum20 = resultCostMap.get("taxNum20").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum50 = resultCostMap.get("taxNum50").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum100 = resultCostMap.get("taxNum100").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum500 = resultCostMap.get("taxNum500").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum1000 = resultCostMap.get("taxNum1000").setScale(2, RoundingMode.HALF_UP).toString();
        String taxNum3000 = resultCostMap.get("taxNum3000").setScale(2, RoundingMode.HALF_UP).toString();

        ResultTimingPulleyPrice timingPulleyPrice = new ResultTimingPulleyPrice(
                OD.setScale(2, RoundingMode.HALF_UP).toString(),
                finishedMass.setScale(2, RoundingMode.HALF_UP).toString(),
                materialSize,
                materialMass.setScale(2, RoundingMode.HALF_UP).toString(),
                materialPrice.setScale(2, RoundingMode.HALF_UP).toString(),
                materialCutOff.setScale(2, RoundingMode.HALF_UP).toString(),
                vehicleATime.setScale(2, RoundingMode.HALF_UP).toString(),
                vehicleBTime.setScale(2, RoundingMode.HALF_UP).toString(),
                latheCost.setScale(2, RoundingMode.HALF_UP).toString(),
                hobbingTime.setScale(2, RoundingMode.HALF_UP).toString(),
                hobbingCost.setScale(2, RoundingMode.HALF_UP).toString(),
                "0",
                "0",
                "0",
                "0",
                pressureRetainingRingTime.setScale(2, RoundingMode.HALF_UP).toString(),
                pressureRetainingRingCost.setScale(2, RoundingMode.HALF_UP).toString(),
                surfaceTreatmentCost.setScale(2, RoundingMode.HALF_UP).toString(),
                flangeCost.setScale(2, RoundingMode.HALF_UP).toString(),
                "0",
                assembleCost.setScale(2, RoundingMode.HALF_UP).toString(),
                packageCost.setScale(2, RoundingMode.HALF_UP).toString(),
                logisticsCost.setScale(2, RoundingMode.HALF_UP).toString(),
                holeModificationTime.setScale(2, RoundingMode.HALF_UP).toString(),
                holeModificationCost.setScale(2, RoundingMode.HALF_UP).toString(),
                materialsPartsCost,
                processCost,
                assessCost,
                retailPrice,
                taxRetailPrice,
                additionalCost.toString(),
                num1,
                num2,
                num3,
                num4,
                num5,
                num10,
                num20,
                num50,
                num100,
                num500,
                num1000,
                num3000,
                taxNum1,
                taxNum2,
                taxNum3,
                taxNum4,
                taxNum5,
                taxNum10,
                taxNum20,
                taxNum50,
                taxNum100,
                taxNum500,
                taxNum1000,
                taxNum3000,
                materialMark,
                tpShape,
                hlTimingPulley
        );
        if (consolePrinting) {
            String resultString = "O.D.:" + OD + "," +
                    "带齿惰轮材料尺寸:" + materialSize + "," +
                    "带齿惰轮材料重量:" + materialMass + "," +
                    "带齿惰轮材料费用:" + materialPrice + "," +
                    "带齿惰轮材料切断:" + materialCutOff + "," +
                    "车A时间:" + vehicleATime + "," +
                    "车B时间:" + vehicleBTime + "," +
                    "车床费用:" + latheCost + "," +
                    "滚齿时间:" + hobbingTime + "," +
                    "滚齿费用:" + hobbingCost + "," +
                    "压挡圈时间:" + pressureRetainingRingTime + "," +
                    "压挡圈费用:" + pressureRetainingRingCost + "," +
                    "成品重量:" + finishedMass + "," +
                    "表面处理费用:" + surfaceTreatmentCost + "," +
                    "挡圈费用:" + flangeCost + "," +
                    "轴承费用:" + bearingCost + "," +
                    "装配费用:" + assembleCost + "," +
                    "包装费用:" + packageCost + "," +
                    "物流费用:" + logisticsCost + "," +
                    "改孔时间:" + holeModificationTime + "," +
                    "改孔费用:" + holeModificationCost + "," +
                    "料件成本:" + materialsPartsCost + "," +
                    "加工成本:" + processCost + "," +
                    "合计成本:" + assessCost + "," +
                    "零售价:" + retailPrice + "," +
                    "含税零售价:" + taxRetailPrice + "," +
                    "额外成本:" + additionalCost + "," +
                    "1件:" + num1 + "," +
                    "2件:" + num2 + "," +
                    "3件:" + num3 + "," +
                    "4件:" + num4 + "," +
                    "5件:" + num5 + "," +
                    "10+价:" + num10 + "," +
                    "20+价:" + num20 + "," +
                    "50+价:" + num50 + "," +
                    "100+价:" + num100 + "," +
                    "500+价:" + num500 + "," +
                    "1000+价:" + num1000 + "," +
                    "3000+价:" + num3000 + "," +
                    "含税1件:" + taxNum1 + "," +
                    "含税2件:" + taxNum2 + "," +
                    "含税3件:" + taxNum3 + "," +
                    "含税4件:" + taxNum4 + "," +
                    "含税5件:" + taxNum5 + "," +
                    "含税10+价:" + taxNum10 + "," +
                    "含税20+价:" + taxNum20 + "," +
                    "含税50+价:" + taxNum50 + "," +
                    "含税100+价:" + taxNum100 + "," +
                    "含税500+价:" + taxNum500 + "," +
                    "含税1000+价:" + taxNum1000 + "," +
                    "含税3000+价:" + taxNum3000;
            String[] pairs = resultString.split(",");

            LinkedHashMap<String, String> resultJsonMap = new LinkedHashMap<>();
            for (String pair : pairs) {
                String[] pairsSon = pair.split(":");
                resultJsonMap.put(pairsSon[0], pairsSon[1]);
            }
            log.info("价格详情 ==> {}", JSON.toJSONString(resultJsonMap));
        }
        if ("1".equals(authority)) {
            ResultTimingPulleyPrice timingPulleyPriceTwo = new ResultTimingPulleyPrice(
                    num1,
                    num2,
                    num3,
                    num4,
                    num5,
                    num10,
                    num20,
                    num50,
                    num100,
                    num500,
                    num1000,
                    num3000,
                    taxNum1,
                    taxNum2,
                    taxNum3,
                    taxNum4,
                    taxNum5,
                    taxNum10,
                    taxNum20,
                    taxNum50,
                    taxNum100,
                    taxNum500,
                    taxNum1000
            );
            return AjaxResult.success(timingPulleyPriceTwo);
        }
        return AjaxResult.success(timingPulleyPrice);
    }

    /**
     * 成品的信息：   O.D.    重量    材料尺寸
     *
     * @param teethNum 齿数
     * @param hlTooth 齿数表
     * @param hlTimingPulley 带齿惰轮表
     * @param materialOdList 材质OD表
     * @param hlBandwidth 齿形带宽表
     * @param hlMaterial 材质表
     * @param consolePrinting 是否输出控制台打印日志
     * @return 结果
     */
    public Map<String, String> resultIgFinishedProductInformationMap(BigDecimal teethNum, HlTooth hlTooth, HlTimingPulley hlTimingPulley,
                                                                     List<HlMaterialOd> materialOdList, HlBandwidth hlBandwidth, HlMaterial hlMaterial,
                                                                     Boolean consolePrinting) {
        Map<String, String> resultIgFinishedProductInformationMap = new HashMap<>();
        BigDecimal π = new BigDecimal(Math.PI);
        BigDecimal two = BigDecimal.valueOf(2);

        // C 周长 = 齿数 X 齿距
        BigDecimal C = teethNum.multiply(hlTooth.getPitch());
        // P.D.
        BigDecimal PD = C.divide(π, 3, RoundingMode.HALF_UP);
        // O.D.
        BigDecimal OD;
        // 若 r0 不为空, P.D. 减去 两倍 的 rO
        if (ObjectUtils.isNotEmpty(hlTooth.getR0())) {
            OD = PD.subtract(hlTooth.getR0()).subtract(hlTooth.getR0());
        } else {
            OD = PD;
        }

        // 如果查询同步轮类型齿数在数据库中有，就用数据库中的O.D.
        if (ObjectUtils.isNotEmpty(hlTimingPulley)) {
            OD = new BigDecimal(hlTimingPulley.getTpOd());
        }
        resultIgFinishedProductInformationMap.put("O.D.", OD.toString());

        // 带齿惰轮材料尺寸
        StringBuilder materialSize = new StringBuilder();
        // 添加余量
        BigDecimal realityOD = OD.add(BigDecimal.valueOf(0.2)).add(BigDecimal.valueOf(0.8));
        // 之后还需在数据库中找个比之大的整数，现实铝棒是不可能生产有小数点位的直径
        realityOD = realityOD.setScale(0, RoundingMode.UP); // 向上取整
        for (HlMaterialOd materialOd : materialOdList) {
            BigDecimal od = BigDecimal.valueOf(materialOd.getOd());
            if (od.compareTo(realityOD) >= 0) {
                realityOD = od;
                break;
            }
        }

        BigDecimal bandwidthW = hlBandwidth.getBandwidthW();
        if (OD.compareTo(BigDecimal.valueOf(80)) > 0) {
            materialSize.append(realityOD).append("*").append(bandwidthW.add(BigDecimal.valueOf(3)).setScale(0, RoundingMode.UP));
        } else {
            materialSize.append(realityOD).append("*").append(bandwidthW.add(BigDecimal.valueOf(2)).setScale(0, RoundingMode.UP));
        }

        String materialSizeString = materialSize.toString();
        String[] split = materialSizeString.split("\\*");

        resultIgFinishedProductInformationMap.put("materialSize", materialSizeString);

        // ac 对应Excel [ AC -- 材料外径 ]
        BigDecimal ac = realityOD;
        // ae 对应Excel [ AE -- 材料长度 ]
        BigDecimal ae = new BigDecimal(split[1]);

        BigDecimal acR = ac.divide(two, 3, RoundingMode.HALF_UP);

        // 带齿惰轮的面积
        BigDecimal multiplyAcR = acR.multiply(acR).multiply(π);

        // 带齿惰轮的面积计算出来了，现在算体积
        BigDecimal V = multiplyAcR.multiply(ae);
        // 材质的密度与单价
        // 密度 kg/m³
        BigDecimal density = hlMaterial.getMaterialDensity();
        // 将体积从立方毫米转换为立方米, 保留六位小数
        BigDecimal volumeInMeters = V.divide(new BigDecimal("1000000000"), 10, RoundingMode.HALF_UP);
        // 材料重量
        // 计算重量, 四舍五入并且保留三位小数
        BigDecimal materialMass = density.multiply(volumeInMeters);
        resultIgFinishedProductInformationMap.put("materialMass", materialMass.toString());

        String materialMark = hlMaterial.getMaterialMark();

        // 成品重量
        // L3/2
        BigDecimal L3 = OD.divide(BigDecimal.valueOf(2), 10, RoundingMode.HALF_UP);
        // W
        BigDecimal mind = new BigDecimal(hlTimingPulley.getTpMinD());
        // W3/2
        BigDecimal W3 = mind.divide(BigDecimal.valueOf(2), 10, RoundingMode.HALF_UP);
        BigDecimal finishedMass = (L3.multiply(L3).multiply(π).subtract(W3.multiply(W3).multiply(π)))
                .multiply(hlBandwidth.getBandwidthW()).divide(new BigDecimal("1000000000"), 10, RoundingMode.HALF_UP)
                .multiply(density);
        resultIgFinishedProductInformationMap.put("finishedMass", finishedMass.toString());


        // 材料费用
        BigDecimal materialPrice = new BigDecimal("0");
        if (
                ObjectUtils.equals("A", materialMark) ||
                        ObjectUtils.equals("H", materialMark) ||
                        ObjectUtils.equals("HK", materialMark) ||
                        ObjectUtils.equals("K", materialMark) ||
                        ObjectUtils.equals("R", materialMark)
        ) {
            materialPrice = materialMass.multiply(BigDecimal.valueOf(23));
        } else if (
                ObjectUtils.equals("F", materialMark) ||
                        ObjectUtils.equals("C", materialMark) ||
                        ObjectUtils.equals("D", materialMark)
        ) {
            materialPrice = materialMass.multiply(BigDecimal.valueOf(6.5));
        } else if (ObjectUtils.equals("S", materialMark)) {
            materialPrice = materialMass.multiply(BigDecimal.valueOf(22));
        }
        resultIgFinishedProductInformationMap.put("materialPrice", materialPrice.toString());

        if (consolePrinting) {
            log.info("带齿惰轮成品的体积mm³ ==> {}", V);
            log.info("带齿惰轮计算出来的O.D. ==> {}", OD);
            log.info("带齿惰轮材料重量 ==> {}", materialMass);
            log.info("带齿惰轮现实材料的O.D. ==> {}", realityOD);
            log.info("带齿惰轮材料尺寸 ==> {}", materialSizeString);
            log.info("带齿惰轮材料费用 ==> {}", materialPrice);
            log.info("带齿惰轮成品的重量 ==> {}", finishedMass);
        }
        return resultIgFinishedProductInformationMap;
    }

    /**
     * 车A时间
     *
     * @param materialSize 带齿惰轮材料尺寸
     * @param OD 带齿惰轮成品的信息:   O.D.
     * @param hlBandwidth 齿形带宽表
     * @param hlTimingPulley 带齿惰轮表
     * @param materialMark 带齿惰轮材质
     * @return 结果
     */
    public BigDecimal resultIgVehicleATime(String materialSize, BigDecimal OD, HlBandwidth hlBandwidth,
                                         HlTimingPulley hlTimingPulley, String materialMark) {

        // =IFS(
        //         OR($H135=""),
        //         IFS(
        //                 OR($D135="A",$D135="H",$D135="HK",$D135="K",$D135="R"),
        //                         N("多肉部分")+((((AC135)/2)^2*PI()-(AD135/2)^2*PI())*((AE135-$N135)/2)+(((AC135)/2)^2*PI()-(($L135+0.3)/2)^2*PI())*((AE135+$N135)/2)+((($L135+0.3)/2)^2*PI()-(($Q135)/2)^2*PI())*(($N135-$M135)/2))/1500+9+
        //                         N("表面粗车")+(($L135+0.3)*PI()*((AE135+$M135)/2)+($Q135)*PI()*(($N135-$M135)/2)+(($L135+0.3)/2)^2*PI()-(($W135-0.2)/2)^2*PI()+($W135-0.2)*PI()*((AE135+$N135)/2))/IF(($L135+$W135)<95.5,($L135+$W135)/2/0.0955*2.2,500*2.2)+12+
        //                         N("表面精车")+((($L135+0.3)/2)^2*PI()-(($W135-0.2)/2)^2*PI()+($Q135)*PI()*(($N135-$M135)/2))/IF(($L135+$W135)<95.5,($L135+$W135)/2/0.0955*0.8,500*0.8)+6+
        //                         N("切断")+IF(AC135>46,0,(AC135)/2.1+1)+10+N("结束"),
        //                 OR($D135="F",$D135="C",$D135="D"),
        //                         N("多肉部分")+((((AC135)/2)^2*PI()-(AD135/2)^2*PI())*((AE135-$N135)/2)+(((AC135)/2)^2*PI()-(($L135+0.3)/2)^2*PI())*((AE135+$N135)/2)+((($L135+0.3)/2)^2*PI()-(($Q135)/2)^2*PI())*(($N135-$M135)/2))/600+9+
        //                         N("表面粗车")+(($L135+0.3)*PI()*((AE135+$M135)/2)+($Q135)*PI()*(($N135-$M135)/2)+(($L135+0.3)/2)^2*PI()-(($W135-0.2)/2)^2*PI()+($W135-0.2)*PI()*((AE135+$N135)/2))/IF(($L135+$W135)<95.5,($L135+$W135)/2/0.0955*1.2,500*1.2)+12+
        //                         N("表面精车")+((($L135+0.3)/2)^2*PI()-(($W135-0.2)/2)^2*PI()+($Q135)*PI()*(($N135-$M135)/2))/IF(($L135+$W135)<95.5,($L135+$W135)/2/0.0955*0.5,500*0.5)+6+
        //                         N("切断")+IF(AC135>46,0,(AC135)/1.1+1)+10+N("结束")))

        String[] materialSizeSplit = materialSize.split("\\*");
        BigDecimal materialOutsideDiameter = new BigDecimal(materialSizeSplit[0]);
        BigDecimal materialLength = new BigDecimal(materialSizeSplit[1]);
        BigDecimal two = new BigDecimal("2");

        // AE - N
        BigDecimal AEjN = materialLength.subtract(hlBandwidth.getBandwidthW());
        // AE + N
        BigDecimal AEjjN = materialLength.add(hlBandwidth.getBandwidthW());
        // Q
        BigDecimal tpE = new BigDecimal(hlTimingPulley.getTpE());
        // N - M
        BigDecimal NjM = hlBandwidth.getBandwidthW().subtract(hlBandwidth.getBandwidthA());
        // AE + M
        BigDecimal AEjjM = materialLength.add(hlBandwidth.getBandwidthA());
        // W
        BigDecimal mind = new BigDecimal(hlTimingPulley.getTpMinD());



        // π 圆周率
        BigDecimal π = new BigDecimal(Math.PI);
        // (AC135/2)^2*PI()
        BigDecimal AC3AC3PI = materialOutsideDiameter.divide(two, 10, RoundingMode.HALF_UP).multiply(materialOutsideDiameter.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);materialOutsideDiameter.divide(two, 10, RoundingMode.HALF_UP).multiply(materialOutsideDiameter.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // (AD135/2)^2*PI()
        BigDecimal AD3AD3PI = new BigDecimal("0");
        // (AE135-$N135)/2
        BigDecimal AE3jN3 = AEjN.divide(two, 10, RoundingMode.HALF_UP);
        // $L135+0.3
        BigDecimal L3jj3 = OD.add(BigDecimal.valueOf(0.3));
        // ($L135+0.3)/2
        BigDecimal L3j03 = L3jj3.divide(two, 10, RoundingMode.HALF_UP);
        // ($L135+0.3)*PI()
        BigDecimal L3jj03PI = L3jj3.multiply(π);
        // (($L135+0.3)/2)^2*PI()
        BigDecimal L3j03L3j03PI = L3j03.multiply(L3j03).multiply(π);
        // (AE135+$N135)/2
        BigDecimal AE3jjN3 = AEjjN.divide(two, 10, RoundingMode.HALF_UP);
        // ($Q135/2)^2*PI()
        BigDecimal Q3Q3PI = tpE.divide(two, 10, RoundingMode.HALF_UP).multiply(tpE.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // ($N135-$M135)/2
        BigDecimal N3jM3 = NjM.divide(two, 10, RoundingMode.HALF_UP);
        // (AE135+$M135)/2
        BigDecimal AE3jjM3 = AEjjM.divide(two, 10, RoundingMode.HALF_UP);
        // ($Q135)*PI()
        BigDecimal Q3PI = tpE.multiply(π);
        // ($W135-0.2)
        BigDecimal Wj2 = mind.subtract(BigDecimal.valueOf(0.2));
        BigDecimal Wj2PI = Wj2.multiply(π);
        // ($W135-0.2)/2
        BigDecimal W3j02 = Wj2.divide(two, 10, RoundingMode.HALF_UP);
        // (($W135-0.2)/2)^2*PI()
        BigDecimal W3j02W3j02PI = W3j02.multiply(W3j02).multiply(π);

        // L + W
        BigDecimal LjjW =  OD.add(mind);

        // 多肉部分
        BigDecimal succulentPart = (AC3AC3PI.subtract(AD3AD3PI)).multiply(AE3jN3)
                .add((AC3AC3PI.subtract(L3j03L3j03PI)).multiply(AE3jjN3))
                .add((L3j03L3j03PI.subtract(Q3Q3PI)).multiply(N3jM3));

        // 表面粗车
        BigDecimal surfaceRoughTurning = L3jj03PI.multiply(AE3jjM3)
                .add(Q3PI.multiply(N3jM3))
                .add(L3j03L3j03PI).subtract(W3j02W3j02PI)
                .add(Wj2PI.multiply(AE3jjN3));
        BigDecimal divideConstantTrue = (LjjW.divide(two, 10, RoundingMode.HALF_UP)).divide(BigDecimal.valueOf(0.0955), 10, RoundingMode.HALF_UP);

        // 表面精车
        BigDecimal surfaceFinishing = L3j03L3j03PI.subtract(W3j02W3j02PI).add(Q3PI.multiply(N3jM3));

        // 切断
        BigDecimal cutOff = new BigDecimal(0);
        if (
                ObjectUtils.equals("A", materialMark) ||
                        ObjectUtils.equals("H", materialMark) ||
                        ObjectUtils.equals("HK", materialMark) ||
                        ObjectUtils.equals("K", materialMark) ||
                        ObjectUtils.equals("R", materialMark)
        ) {
            succulentPart = succulentPart.divide(BigDecimal.valueOf(1500), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9));

            if (LjjW.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                surfaceRoughTurning = surfaceRoughTurning.divide(divideConstantTrue.multiply(BigDecimal.valueOf(2.2)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(12));
                surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.8)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
            } else {
                surfaceRoughTurning = surfaceRoughTurning.divide(BigDecimal.valueOf(500 * 2.2), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(12));
                surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.8)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
            }

            if (materialOutsideDiameter.compareTo(BigDecimal.valueOf(46)) <= 0) {
                cutOff = materialOutsideDiameter.divide(BigDecimal.valueOf(2.1), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(1)).add(BigDecimal.valueOf(10));
            } else {
                cutOff = cutOff.add(BigDecimal.valueOf(10));
            }
        } else if (
                ObjectUtils.equals("F", materialMark) ||
                        ObjectUtils.equals("C", materialMark) ||
                        ObjectUtils.equals("D", materialMark)
        ) {
            succulentPart = succulentPart.divide(BigDecimal.valueOf(600), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9));

            if (LjjW.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                surfaceRoughTurning = surfaceRoughTurning.divide(divideConstantTrue.multiply(BigDecimal.valueOf(1.2)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(12));
                surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.5)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
            } else {
                surfaceRoughTurning = surfaceRoughTurning.divide(BigDecimal.valueOf(500 * 1.2), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(12));
                surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.5), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
            }

            if (materialOutsideDiameter.compareTo(BigDecimal.valueOf(46)) <= 0) {
                cutOff = materialOutsideDiameter.divide(BigDecimal.valueOf(1.1), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(1)).add(BigDecimal.valueOf(10));
            } else {
                cutOff = cutOff.add(BigDecimal.valueOf(10));
            }
        } else {
            return new BigDecimal("0");
        }
        return succulentPart.add(surfaceRoughTurning).add(surfaceFinishing).add(cutOff);
    }

    /**
     * 车B时间
     *
     * @param materialSize 带齿惰轮材料尺寸
     * @param OD 带齿惰轮成品的信息:   O.D.
     * @param hlBandwidth 齿形带宽表
     * @param hlTimingPulley 带齿惰轮表
     * @param materialMark 带齿惰轮材质
     * @return 结果
     */
    public BigDecimal resultIgVehicleBTime(String materialSize, BigDecimal OD, HlBandwidth hlBandwidth,
                                           HlTimingPulley hlTimingPulley, String materialMark) {

        // =IFS(
        //         OR($H135=""),
        //         IFS(
        //                 OR($D135="A",$D135="H",$D135="HK",$D135="K",$D135="R"),
        //                         N("多肉部分")+(((($L135+0.3)/2)^2*PI()-(($W135-0.2)/2)^2*PI())*((AE135-$N135)/2)+((($L135+0.3)/2)^2*PI()-(($Q135)/2)^2*PI())*(($N135-$M135)/2))/1500+6+
        //                         N("表面粗车")+(0)/IF(($L135+$W135)<95.5,($L135+$W135)/2/0.0955*2.2,500*2.2)+0+
        //                         N("表面精车")+((($L135+0.3)/2)^2*PI()-(($W135-0.2)/2)^2*PI()+($W135)*PI()*($N135)+($Q135)*PI()*(($N135-$M135)/2))/IF(($L135+$W135)<95.5,($L135+$W135)/2/0.0955*0.8,500*0.8)+9+10+
        //                         N("结束"),
        //                 OR($D135="F",$D135="C",$D135="D"),
        //                         N("多肉部分")+(((($L135+0.3)/2)^2*PI()-(($W135-0.2)/2)^2*PI())*((AE135-$N135)/2)+((($L135+0.3)/2)^2*PI()-(($Q135)/2)^2*PI())*(($N135-$M135)/2))/600+6+
        //                         N("表面粗车")+(0)/IF(($L135+$W135)<95.5,($L135+$W135)/2/0.0955*1.2,500*1.2)+0+
        //                         N("表面精车")+((($L135+0.3)/2)^2*PI()-(($W135-0.2)/2)^2*PI()+($W135)*PI()*($N135)+($Q135)*PI()*(($N135-$M135)/2))/IF(($L135+$W135)<95.5,($L135+$W135)/2/0.0955*0.5,500*0.5)+9+10+
        //                         N("结束")))

        String[] materialSizeSplit = materialSize.split("\\*");
        BigDecimal materialOutsideDiameter = new BigDecimal(materialSizeSplit[0]);
        BigDecimal materialLength = new BigDecimal(materialSizeSplit[1]);
        BigDecimal two = new BigDecimal("2");

        // AE - N
        BigDecimal AEjN = materialLength.subtract(hlBandwidth.getBandwidthW());
        // AE + N
        BigDecimal AEjjN = materialLength.add(hlBandwidth.getBandwidthW());
        // Q
        BigDecimal tpE = new BigDecimal(hlTimingPulley.getTpE());
        // N - M
        BigDecimal NjM = hlBandwidth.getBandwidthW().subtract(hlBandwidth.getBandwidthA());
        // AE + M
        BigDecimal AEjjM = materialLength.add(hlBandwidth.getBandwidthA());
        // W
        BigDecimal mind = new BigDecimal(hlTimingPulley.getTpMinD());



        // π 圆周率
        BigDecimal π = new BigDecimal(Math.PI);
        // (AE135-$N135)/2
        BigDecimal AE3jN3 = AEjN.divide(two, 10, RoundingMode.HALF_UP);
        // $L135+0.3
        BigDecimal L3jj3 = OD.add(BigDecimal.valueOf(0.3));
        // ($L135+0.3)/2
        BigDecimal L3j03 = L3jj3.divide(two, 10, RoundingMode.HALF_UP);
        // (($L135+0.3)/2)^2*PI()
        BigDecimal L3j03L3j03PI = L3j03.multiply(L3j03).multiply(π);
        // ($Q135/2)^2*PI()
        BigDecimal Q3Q3PI = tpE.divide(two, 10, RoundingMode.HALF_UP).multiply(tpE.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // ($N135-$M135)/2
        BigDecimal N3jM3 = NjM.divide(two, 10, RoundingMode.HALF_UP);
        // ($Q135)*PI()
        BigDecimal Q3PI = tpE.multiply(π);
        // ($W135-0.2)
        BigDecimal Wj2 = mind.subtract(BigDecimal.valueOf(0.2));
        // ($W135-0.2)/2
        BigDecimal W3j02 = Wj2.divide(two, 10, RoundingMode.HALF_UP);
        // (($W135-0.2)/2)^2*PI()
        BigDecimal W3j02W3j02PI = W3j02.multiply(W3j02).multiply(π);
        // ($W135)*PI()
        BigDecimal W3PI = mind.multiply(π);

        // L + W
        BigDecimal LjjW =  OD.add(mind);

        // 多肉部分
        BigDecimal succulentPart = (L3j03L3j03PI.subtract(W3j02W3j02PI)).multiply(AE3jN3)
                .add((L3j03L3j03PI.subtract(Q3Q3PI)).multiply(N3jM3));

        // 表面粗车
        BigDecimal surfaceRoughTurning = new BigDecimal(0);
        BigDecimal divideConstantTrue = (LjjW.divide(two, 10, RoundingMode.HALF_UP)).divide(BigDecimal.valueOf(0.0955), 10, RoundingMode.HALF_UP);

        // 表面精车
        BigDecimal surfaceFinishing = L3j03L3j03PI.subtract(W3j02W3j02PI).add(W3PI.multiply(hlBandwidth.getBandwidthW()))
                .add(Q3PI.multiply(N3jM3));

        // 切断
        BigDecimal cutOff = new BigDecimal(0);
        if (
                ObjectUtils.equals("A", materialMark) ||
                        ObjectUtils.equals("H", materialMark) ||
                        ObjectUtils.equals("HK", materialMark) ||
                        ObjectUtils.equals("K", materialMark) ||
                        ObjectUtils.equals("R", materialMark)
        ) {
            succulentPart = succulentPart.divide(BigDecimal.valueOf(1500), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));

            if (LjjW.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.8)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9)).add(BigDecimal.valueOf(10));
            } else {
                surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.8), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9)).add(BigDecimal.valueOf(10));
            }
        } else if (
                ObjectUtils.equals("F", materialMark) ||
                        ObjectUtils.equals("C", materialMark) ||
                        ObjectUtils.equals("D", materialMark)
        ) {
            succulentPart = succulentPart.divide(BigDecimal.valueOf(600), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));

            if (LjjW.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.5)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9)).add(BigDecimal.valueOf(10));
            } else {
                surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.5), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(9)).add(BigDecimal.valueOf(10));
            }
        } else {
            return new BigDecimal("0");
        }
        return succulentPart.add(surfaceRoughTurning).add(surfaceFinishing).add(cutOff);
    }

    /**
     * 根据轴承型号计算轴承费用
     * @param tpShape 轴承布局
     * @param bearing 轴承型号
     * @return 结果
     */
    public BigDecimal resultBearingCost(String tpShape, String bearing) {
        BigDecimal bearingCost = new BigDecimal("0");
        HlBearing hlBearing = hlBearingService.selectOne(tpShape, bearing);
        if (ObjectUtils.isNotEmpty(hlBearing)) {
            if ("A".equals(tpShape)) {
                bearingCost = hlBearing.getBearingPrice();
            } else {
                bearingCost = hlBearing.getBearingPrice().multiply(BigDecimal.valueOf(2));
            }
        }
        return bearingCost;
    }

    /**
     * 改孔时间
     * @param hlTimingPulley 带齿惰轮表
     * @param OD 带齿惰轮成品的信息:   O.D.
     * @param hlBandwidth 齿形带宽表
     * @param materialMark 带齿惰轮材质
     * @return 结果
     */
    public BigDecimal resultIgHoleModificationTime(HlTimingPulley hlTimingPulley, BigDecimal OD, HlBandwidth hlBandwidth,
                                                   String materialMark){
        // π 圆周率
        BigDecimal π = new BigDecimal(Math.PI);
        BigDecimal two = new BigDecimal("2");
        // X
        BigDecimal tpMaxD = new BigDecimal(hlTimingPulley.getTpMaxD());
        // ($X75/2)^2*PI()
        BigDecimal X3X3PI = tpMaxD.divide(two, 10, RoundingMode.HALF_UP).multiply(tpMaxD.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // W
        BigDecimal mind = new BigDecimal(hlTimingPulley.getTpMinD());
        // ($W75/2)^2*PI()
        BigDecimal W3W3PI = mind.divide(two, 10, RoundingMode.HALF_UP).multiply(mind.divide(two, 10, RoundingMode.HALF_UP)).multiply(π);
        // L + W
        BigDecimal LjjW =  OD.add(mind);

        // 多肉部分
        BigDecimal succulentPart = new BigDecimal(0);

        // 表面粗车
        BigDecimal surfaceRoughTurning = new BigDecimal(0);
        BigDecimal divideConstantTrue = (LjjW.divide(two, 10, RoundingMode.HALF_UP)).divide(BigDecimal.valueOf(0.0955), 10, RoundingMode.HALF_UP);

        // 表面精车
        BigDecimal surfaceFinishing = (X3X3PI.subtract(W3W3PI)).multiply(hlBandwidth.getBandwidthW());

        // 切断
        BigDecimal cutOff = new BigDecimal(0).add(BigDecimal.valueOf(20));

        if (
                ObjectUtils.equals("A", materialMark) ||
                        ObjectUtils.equals("H", materialMark) ||
                        ObjectUtils.equals("HK", materialMark) ||
                        ObjectUtils.equals("K", materialMark) ||
                        ObjectUtils.equals("R", materialMark)
        ) {
            if (LjjW.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(1.2)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
            } else {
                surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 1.2), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
            }
        } else if (
                ObjectUtils.equals("F", materialMark) ||
                        ObjectUtils.equals("C", materialMark) ||
                        ObjectUtils.equals("D", materialMark)
        ) {
            succulentPart = surfaceFinishing.divide(BigDecimal.valueOf(600), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));

            if (LjjW.compareTo(BigDecimal.valueOf(95.5)) < 0) {
                surfaceFinishing = surfaceFinishing.divide(divideConstantTrue.multiply(BigDecimal.valueOf(0.5)), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
            } else {
                surfaceFinishing = surfaceFinishing.divide(BigDecimal.valueOf(500 * 0.5), 10, RoundingMode.HALF_UP).add(BigDecimal.valueOf(6));
            }
        } else {
            return new BigDecimal("0");
        }
        return succulentPart.add(surfaceRoughTurning).add(surfaceFinishing).add(cutOff);
    }

    /**
     * 改孔费用
     * @param holeModificationTime 改孔时间
     * @return 结果
     */
    public BigDecimal resultIgHoleModificationCost(BigDecimal holeModificationTime) {
        return holeModificationTime.divide(BigDecimal.valueOf(3600), 10, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(45));
    }

    /**
     * 带齿惰轮成本信息
     * 料件成本 materialsPartsCost 加工成本 processCost 合计成本 assessCost
     * 零售价 retailPrice   含税零售 价 taxRetailPrice
     */
    public HashMap<String, BigDecimal> resultIgCostMap(String tpShape, BigDecimal ag, BigDecimal ah,
                                                       BigDecimal ar, BigDecimal as, BigDecimal aq,
                                                       BigDecimal ax, BigDecimal ak, BigDecimal am,
                                                       BigDecimal ao, BigDecimal aw, BigDecimal dc,
                                                       BigDecimal additionalCost, BigDecimal assembleCost) {

        // =IFS(
        //         OR($H75=""),
        //         IFS(
        //                 OR($D75="A",$D75="H",$D75="HK",$D75="K",$D75="R"),
        //                 N("多肉部分")+(0)+
        //                         N("表面粗车")+(0)+
        //                         N("表面精车")+((($X75/2)^2*PI()-($W75/2)^2*PI())*($N75))/IF(($L75+$W75)<95.5,($L75+$W75)/2/0.0955*1.2,500*1.2)+6+
        //                         N("切断")+(0)+
        //                         N("结束"),
        //                 OR($D75="F",$D75="C",$D75="D"),
        //                 N("多肉部分")+((($X75/2)^2*PI()-($W75/2)^2*PI())*($N75))/600+9+
        //                         N("表面粗车")+(0)+
        //                         N("表面精车")+((($X75/2)^2*PI()-($W75/2)^2*PI())*($N75))/IF(($L75+$W75)<95.5,($L75+$W75)/2/0.0955*0.5,500*0.5)+6+
        //                         N("切断")+(0)+
        //                         N("结束")))+20

        HashMap<String, BigDecimal> costMap = new HashMap<>();
        BigDecimal materialsPartsCost = new BigDecimal("0");
        BigDecimal processCost = new BigDecimal("0");
        BigDecimal assessCost = new BigDecimal("0");
        BigDecimal retailPrice = new BigDecimal("0");
        BigDecimal taxRetailPrice = new BigDecimal("0");
        BigDecimal num1 = new BigDecimal("0");
        BigDecimal num2 = new BigDecimal("0");
        BigDecimal num3 = new BigDecimal("0");
        BigDecimal num4 = new BigDecimal("0");
        BigDecimal num5 = new BigDecimal("0");
        BigDecimal num10 = new BigDecimal("0");
        BigDecimal num20 = new BigDecimal("0");
        BigDecimal num50 = new BigDecimal("0");
        BigDecimal num100 = new BigDecimal("0");
        BigDecimal num500 = new BigDecimal("0");
        BigDecimal num1000 = new BigDecimal("0");
        BigDecimal num3000 = new BigDecimal("0");
        BigDecimal taxNum1 = new BigDecimal("0");
        BigDecimal taxNum2 = new BigDecimal("0");
        BigDecimal taxNum3 = new BigDecimal("0");
        BigDecimal taxNum4 = new BigDecimal("0");
        BigDecimal taxNum5 = new BigDecimal("0");
        BigDecimal taxNum10 = new BigDecimal("0");
        BigDecimal taxNum20 = new BigDecimal("0");
        BigDecimal taxNum50 = new BigDecimal("0");
        BigDecimal taxNum100 = new BigDecimal("0");
        BigDecimal taxNum500 = new BigDecimal("0");
        BigDecimal taxNum1000 = new BigDecimal("0");
        BigDecimal taxNum3000 = new BigDecimal("0");

        BigDecimal constant = BigDecimal.valueOf(1.05);


        if (ObjectUtils.equals("A", tpShape)) {
        } else if (ObjectUtils.equals("B", tpShape)) {
        } else if (ObjectUtils.equals("W", tpShape)) {
        }

        // 料件成本
        materialsPartsCost = (ag.add(ah).add(ar).add(as).add(aq).add(ax)).multiply(constant);
        // 加工成本
        processCost = (ak.add(am).add(ao).add(aw).add(assembleCost)).multiply(constant);
        // 合计成本
        assessCost = materialsPartsCost.add(processCost).setScale(2, RoundingMode.HALF_UP);
        // 零售价
        retailPrice = materialsPartsCost.divide(BigDecimal.valueOf(0.9), 10, RoundingMode.HALF_UP).add(processCost.multiply(BigDecimal.valueOf(2))).setScale(2, RoundingMode.HALF_UP);
        // 含税零售价
        taxRetailPrice = retailPrice.multiply(BigDecimal.valueOf(1.13));
        // 改孔费用
        dc = dc.setScale(2, RoundingMode.HALF_UP);

        BigDecimal ZeroPointNine = BigDecimal.valueOf(0.9);
        BigDecimal onePointSixOne = BigDecimal.valueOf(1.61);
        BigDecimal onePointOne = BigDecimal.valueOf(1.1);
        BigDecimal TwoThousand = BigDecimal.valueOf(2000);
        BigDecimal onePointZeroThree = BigDecimal.valueOf(1.03);

        // 1件
        num1 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(1).multiply(onePointOne).divide(BigDecimal.valueOf(1).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(1).add(onePointZeroThree)).divide(BigDecimal.valueOf(1), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(1), 6 ,RoundingMode.HALF_UP));
        taxNum1 = num1.multiply(BigDecimal.valueOf(1.13));
        // 2件
        num2 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(2).multiply(onePointOne).divide(BigDecimal.valueOf(2).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(2).add(onePointZeroThree)).divide(BigDecimal.valueOf(2), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(2), 6 ,RoundingMode.HALF_UP));
        taxNum2 = num2.multiply(BigDecimal.valueOf(1.13));
        // 3件
        num3 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(3).multiply(onePointOne).divide(BigDecimal.valueOf(3).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(3).add(onePointZeroThree)).divide(BigDecimal.valueOf(3), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(3), 6 ,RoundingMode.HALF_UP));
        taxNum3 = num3.multiply(BigDecimal.valueOf(1.13));
        // 4件
        num4 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(4).multiply(onePointOne).divide(BigDecimal.valueOf(4).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(4).add(onePointZeroThree)).divide(BigDecimal.valueOf(4), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(4), 6 ,RoundingMode.HALF_UP));
        taxNum4 = num4.multiply(BigDecimal.valueOf(1.13));
        // 5件
        num5 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(5).multiply(onePointOne).divide(BigDecimal.valueOf(5).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(5).add(onePointZeroThree)).divide(BigDecimal.valueOf(5), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(5), 6 ,RoundingMode.HALF_UP));
        taxNum5 = num5.multiply(BigDecimal.valueOf(1.13));

        // 10件
        num10 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(10).multiply(onePointOne).divide(BigDecimal.valueOf(10).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(10).add(onePointZeroThree)).divide(BigDecimal.valueOf(10), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(10), 6 ,RoundingMode.HALF_UP));
        taxNum10 = num10.multiply(BigDecimal.valueOf(1.13));
        // 20件
        num20 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(20).multiply(onePointOne).divide(BigDecimal.valueOf(20).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(20).add(onePointZeroThree)).divide(BigDecimal.valueOf(20), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(20), 6 ,RoundingMode.HALF_UP));
        taxNum20 = num20.multiply(BigDecimal.valueOf(1.13));
        // 50件
        num50 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(50).multiply(onePointOne).divide(BigDecimal.valueOf(50).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(50).add(onePointZeroThree)).divide(BigDecimal.valueOf(50), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(50), 6 ,RoundingMode.HALF_UP));
        taxNum50 = num50.multiply(BigDecimal.valueOf(1.13));
        // 100件
        num100 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(100).multiply(onePointOne).divide(BigDecimal.valueOf(100).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(100).add(onePointZeroThree)).divide(BigDecimal.valueOf(100), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(100), 6 ,RoundingMode.HALF_UP));
        taxNum100 = num100.multiply(BigDecimal.valueOf(1.13));
        // 500件
        num500 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(500).multiply(onePointOne).divide(BigDecimal.valueOf(500).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(500).add(onePointZeroThree)).divide(BigDecimal.valueOf(500), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(500), 6 ,RoundingMode.HALF_UP));
        taxNum500 = num500.multiply(BigDecimal.valueOf(1.13));
        // 1000件
        num1000 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(1000).multiply(onePointOne).divide(BigDecimal.valueOf(1000).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(1000).add(onePointZeroThree)).divide(BigDecimal.valueOf(1000), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(1000), 6 ,RoundingMode.HALF_UP));
        taxNum1000 = num1000.multiply(BigDecimal.valueOf(1.13));
        // 3000件
        num3000 = (materialsPartsCost.divide(ZeroPointNine, 6, RoundingMode.HALF_UP).add(processCost.multiply(onePointSixOne.subtract(BigDecimal.valueOf(3000).multiply(onePointOne).divide(BigDecimal.valueOf(3000).add(TwoThousand), 6, RoundingMode.HALF_UP))))).multiply(BigDecimal.valueOf(3000).add(onePointZeroThree)).divide(BigDecimal.valueOf(3000), 6 ,RoundingMode.HALF_UP).add(additionalCost.divide(BigDecimal.valueOf(3000), 6 ,RoundingMode.HALF_UP));
        taxNum3000 = num3000.multiply(BigDecimal.valueOf(1.13));

        costMap.put("materialsPartsCost", materialsPartsCost);
        costMap.put("processCost", processCost);
        costMap.put("assessCost", assessCost);

        costMap.put("retailPrice", retailPrice);
        costMap.put("taxRetailPrice", taxRetailPrice);

        costMap.put("num1", num1);
        costMap.put("num2", num2);
        costMap.put("num3", num3);
        costMap.put("num4", num4);
        costMap.put("num5", num5);
        costMap.put("num10", num10);
        costMap.put("num20", num20);
        costMap.put("num50", num50);
        costMap.put("num100", num100);
        costMap.put("num500", num500);
        costMap.put("num1000", num1000);
        costMap.put("num3000", num3000);

        costMap.put("taxNum1", taxNum1);
        costMap.put("taxNum2", taxNum2);
        costMap.put("taxNum3", taxNum3);
        costMap.put("taxNum4", taxNum4);
        costMap.put("taxNum5", taxNum5);
        costMap.put("taxNum10", taxNum10);
        costMap.put("taxNum20", taxNum20);
        costMap.put("taxNum50", taxNum50);
        costMap.put("taxNum100", taxNum100);
        costMap.put("taxNum500", taxNum500);
        costMap.put("taxNum1000", taxNum1000);
        costMap.put("taxNum3000", taxNum3000);
        return costMap;
    }


    /**
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     */


    /**
     * 查询同步轮
     *
     * @param tpId 同步轮主键
     * @return 同步轮
     */
    @Override
    public HlTimingPulley selectHlTimingPulleyByTpId(Long tpId)
    {
        return hlTimingPulleyMapper.selectHlTimingPulleyByTpId(tpId);
    }

    /**
     * 查询同步轮列表
     *
     * @param hlTimingPulley 同步轮
     * @return 同步轮
     */
    @Override
    public List<HlTimingPulley> selectHlTimingPulleyList(HlTimingPulley hlTimingPulley)
    {
        return hlTimingPulleyMapper.selectHlTimingPulleyList(hlTimingPulley);
    }

    /**
     * 新增同步轮
     *
     * @param hlTimingPulley 同步轮
     * @return 结果
     */
    @Override
    public int insertHlTimingPulley(HlTimingPulley hlTimingPulley)
    {
        return hlTimingPulleyMapper.insertHlTimingPulley(hlTimingPulley);
    }

    /**
     * 修改同步轮
     *
     * @param hlTimingPulley 同步轮
     * @return 结果
     */
    @Override
    public int updateHlTimingPulley(HlTimingPulley hlTimingPulley)
    {
        return hlTimingPulleyMapper.updateHlTimingPulley(hlTimingPulley);
    }

    /**
     * 批量删除同步轮
     *
     * @param tpIds 需要删除的同步轮主键
     * @return 结果
     */
    @Override
    public int deleteHlTimingPulleyByTpIds(Long[] tpIds)
    {
        return hlTimingPulleyMapper.deleteHlTimingPulleyByTpIds(tpIds);
    }

    /**
     * 删除同步轮信息
     *
     * @param tpId 同步轮主键
     * @return 结果
     */
    @Override
    public int deleteHlTimingPulleyByTpId(Long tpId)
    {
        return hlTimingPulleyMapper.deleteHlTimingPulleyByTpId(tpId);
    }
}
